Expand description
Literal parsing modules for the AIM expression grammar.
This module provides parsers for all literal value types in the AIM expression language, including numbers, dates, and text. Each sub-module handles a specific type of literal with its own parsing rules and format requirements.
Literal values are the fundamental building blocks of AIM expressions. They represent concrete values that don’t require evaluation and serve as the basis for type promotion and conversion operations throughout the expression evaluation system.
§Literal Types
- Numbers - Integers, floating-point numbers, and scientific notation via
number - Dates - ISO 8601 date and datetime formats via
date - Text - Quoted strings and tagged content via
text
§Usage
The primary entry points are the individual parse functions exported from each submodule:
use aimx::literals::{parse_number, parse_date, parse_text};
// Parse a number
let (_, num) = parse_number("42.5").unwrap();
assert_eq!(num, 42.5);
// Parse a date
let (_, date) = parse_date("2023-01-15").unwrap();
// Date handling uses jiff::civil::DateTime
// Parse text
let (_, text) = parse_text("\"hello world\"").unwrap();
assert_eq!(text, "hello world");These parsers are used internally by the main literal parser crate::literal::parse_literal
but can also be used directly when specific literal types need to be parsed.
§Integration with AIMX
Literal parsing is part of the broader expression parsing system. Most users will interact
with the main parser crate::aimx_parse which automatically handles literal parsing:
use aimx::{aimx_parse, ExpressionLike, Context};
let expression = aimx_parse("42 + 10.5");
let mut context = Context::new();
let result = expression.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "52.5");§Related Modules
crate::literal- Main literal representation and parsing interfacecrate::expression- Top-level expression parsing and evaluation
Re-exports§
pub use date::parse_date;pub use number::parse_number;pub use number::parse_unsigned;pub use text::parse_block;pub use text::parse_tag;pub use text::parse_text;