pub fn parse_literal(input: &str) -> IResult<&str, Literal>Expand description
Parse a literal value from input text according to AIM grammar rules.
This is the main entry point for parsing literal values in AIM expressions. It attempts to parse the input as one of the supported literal types: boolean, date, number, task, or text. The parser uses a precedence order that matches the grammar’s operator precedence rules.
§Supported Literal Types
- Boolean:
trueorfalse(case-sensitive) - Date: Various date formats supported by
parse_date - Number: Floating-point numbers with optional sign and decimal point
- Task: Task literals with optional status:
[+] text,[-] text,[ ] text - Text: Quoted strings using
parse_text
§Arguments
input- A string slice containing the literal to parse
§Returns
IResult<&str, Literal>- A nom parser result containing:- Remaining input after parsing the literal
- Parsed
Literalvalue
§Examples
use aimx::{parse_literal, Literal};
// Parse boolean
let (remaining, literal) = parse_literal("true").unwrap();
assert_eq!(remaining, "");
assert_eq!(literal, Literal::Bool(true));
// Parse number
let (remaining, literal) = parse_literal("42.5").unwrap();
assert_eq!(remaining, "");
assert_eq!(literal, Literal::Number(42.5));
// Parse task
let (remaining, literal) = parse_literal("[+] 'Complete task'").unwrap();
assert_eq!(remaining, "");
assert_eq!(literal, Literal::Task(Some(true), "Complete task".to_string()));
// Parse text
let (remaining, literal) = parse_literal("'hello world'").unwrap();
assert_eq!(remaining, "");
assert_eq!(literal, Literal::Text("hello world".to_string()));§Error Handling
Returns a nom error if the input cannot be parsed as any supported literal type. The parser will try each type in order until one succeeds or all fail.
§See Also
parse_bool- Boolean-specific parserparse_task- Task-specific parserparse_date,parse_number,parse_text- Type-specific parsers incrate::literalsmodule