Skip to main content

base_expr_precedence

Function base_expr_precedence 

Source
fn base_expr_precedence<'db, const SELECT: u32>(
    db: &'db dyn Db,
    parser: &mut Parser<'_, 'db>,
) -> Result<Option<AstExprKind<'db>>, ParseFail<'db>>
Expand description

Parses base expressions - the “atoms” of the expression grammar.

Base expressions are those that don’t involve operators or complex precedence:

  • Literals: Numbers, strings, booleans (42, "hello", true)
  • Identifiers: Variable names and self
  • Control flow: if expressions, return statements
  • Constructors: Type { field: value } (when SELECT_STRUCT is enabled)
  • Unary operators: !expr, -expr

This function is called at the highest precedence level, meaning these expressions bind most tightly and are parsed first before any binary operators.

§String Literal Handling

String literals are parsed through [Literal::opt_parse], which:

  1. Recognizes TokenKind::Literal(LiteralKind::String, text) tokens
  2. Creates a Literal AST node with the raw tokenizer text
  3. Wraps it in AstExprKind::Literal for the expression tree

Note: The current implementation has a bug where escape sequences are validated but never interpreted - "hello\nworld" remains as literal \n characters.