Expand description
Primary expression parsing and evaluation for the AIMX grammar.
This module provides the infrastructure for parsing and evaluating primary expressions, which form the foundation of the AIMX (Agentic Inference Markup Expressions) language. Primary expressions represent the most fundamental building blocks that all other expressions are built upon, including literals, variable references, and parenthesized expressions.
Primary expressions have the highest precedence in the AIMX grammar hierarchy and are the first expressions parsed when building the abstract syntax tree (AST).
§Primary Expression Types
- Literals - Boolean, Date, Number, Task, and Text values
- References - Variable and field references using dot notation
- Parentheses - Grouped expressions
(expression)that override precedence
§Examples
42 // number literal
"hello" // text literal
true // boolean literal
foo // simple variable reference
data.items // chained field reference
(1 + 2) * 3 // parenthesized expression§AST Flattening Optimization
The Primary enum includes variants for all higher-level expression types as part of an
AST flattening optimization. This allows expressions that consist solely of primary
components to be evaluated more efficiently without deep recursion through the expression
hierarchy.
§Usage
Primary expressions are typically used internally by the AIMX parser but can also be used directly for parsing simple expressions or when working with literals and references in isolation.
use aimx::{Primary};
use aimx::expressions::{parse_primary};
use aimx::Literal;
// Parse a simple literal
let (remaining, primary) = parse_primary("42").unwrap();
assert_eq!(remaining, "");
assert!(matches!(primary, Primary::Literal(Literal::Number(_))));
// Parse a reference
let (remaining, primary) = parse_primary("variable_name").unwrap();
assert_eq!(remaining, "");
assert!(matches!(primary, Primary::Reference(_)));Enums§
- Primary
- Represents a primary expression in the AIMX grammar.
Functions§
- parse_
parentheses - Parse a parenthesized expression.
- parse_
primary - Parse a primary expression from text input.