caffeine_lang/cql/parser
Types
Values
pub fn debug_exp(exp: Exp) -> String
Pretty print an expression tree for debugging. Useful for visualizing the AST structure.
pub fn do_parse_expr(input: String) -> Result(Exp, String)
Core parsing logic. Handles two cases:
- Fully parenthesized expressions: (expr) -> unwrap and parse inner
- Non-parenthesized: try to split by operators in precedence order
Operator precedence (lowest to highest): +, -, *, / We search for lowest precedence first to build correct AST structure.
pub fn is_balanced_parens(
input: String,
pos: Int,
count: Int,
) -> Bool
Check if parentheses are balanced from position pos with initial count.
Args:
- input: The string to check
- pos: Starting position (0-indexed)
- count: Initial parenthesis depth (1 means we’re inside one open paren)
Returns True only if:
- Count reaches exactly 0 at the end of the string
- Count never reaches 0 before the end (no premature closing)
This ensures that for “(A + B)”, starting at pos=1 with count=1, we verify the closing ‘)’ is at the very end.
pub fn parse_expr(input: String) -> Result(ExpContainer, String)
Parse an expression string into an ExpContainer.
Examples:
- “A + B” -> Addition of A and B
- “(A + B) / C” -> Division with parenthesized addition
- “A * B + C / D - E” -> Mixed operators with precedence