Source: src/parser/expr.lx
Parses Luma expressions into AST nodes (a Pratt / precedence-climbing parser).
A token nud/led dispatch table drives parsing of literals, operators,
calls, indexing, member access, struct expressions, and the __alloc__,
__free__, __cast__, __input__, __system__, __syscall__, and
__sizeof__ builtins.
Resolves a single escape character (the character after a \) to its byte
value; unknown escapes pass the character through unchanged.
unescape_char -> fn(
c: byte
) byte
Returns the value of a hex digit character (0-9, a-f, A-F), or
-1 if c is not a hex digit.
hex_digit_val -> fn(
c: byte
) i64
Returns a heap-allocated copy of s with escape sequences resolved.
Handles \n, \t, \r, \0, \\, \', \", and \xHH hex-byte
escapes; unknown escapes pass through unchanged.
#returns_ownership
unescape_str -> fn(
s: *byte
) *byte
Returns: Newly allocated, NUL-terminated string; the caller owns the buffer.
#returns_ownership
enstruct -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
#returns_ownership
binary -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
is_shift_right -> fn(
p: *PARS::Parser
) bool
current_bp -> fn(
p: *PARS::Parser
) i64
#returns_ownership
try_generic_instantiation -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
#returns_ownership
call -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
#returns_ownership
assign -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
#returns_ownership
prefix -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
#returns_ownership
primary -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
unary -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
group -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
array -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
index -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
deref -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
addr -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
_alloc -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
_free -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
_cast -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
_input -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
_system -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
syscall -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
_sizeof -> fn(
p: *PARS::Parser
) *AST::AstNode
#returns_ownership
estruct -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses the left-hand operand (the "null denotation") of an expression, dispatching on the current token. Lexer-detected error tokens are consumed and reported without an extra diagnostic.
#returns_ownership
nud -> fn(
p: *PARS::Parser
) *AST::AstNode
Returns: The parsed node, or null after recording an error.
Parses an infix/postfix continuation (the "left denotation") for left at
binding power bp, dispatching on the current token.
#returns_ownership
led -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
Returns: The combined node, or null after recording an error.
Speculatively parses left '<' Type (',' Type)* '>' as a generic
call/struct-literal/member site and attaches the type arguments, provided
the (')/{/:: following shape holds.
On failure the parser and error state are rolled back to the savepoint so
the < can be parsed as an ordinary comparison.
#returns_ownership
try_generic_instantiation -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
Parses a full expression at binding power bp using the nud/led
loop, stopping once the current token binds tighter than bp.
pub #returns_ownership
parse_expr -> fn(
p: *PARS::Parser,
bp: i64
) *AST::AstNode
Returns: The expression node, or null on error.
Parses left { name: value, ... } — a named struct literal — into a
struct-expression AST node.
#returns_ownership
enstruct -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
Parses a binary operator: consumes the operator token (plus a second >
when it forms a right-shift) and parses the right operand at bp.
#returns_ownership
binary -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
Returns true when the current and next tokens are both > (adjacent >
tokens after a comparison could only form a right-shift).
is_shift_right -> fn(
p: *PARS::Parser
) bool
Returns the binding power of the current token, treating >> as a shift.
current_bp -> fn(
p: *PARS::Parser
) i64
Parses left(args) into a call node.
#returns_ownership
call -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
Parses left = value into an assignment node.
#returns_ownership
assign -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
Parses a postfix/prefix expression on left: indexing left[...], member
access left.m / left::m, or postfix ++/--.
#returns_ownership
prefix -> fn(
p: *PARS::Parser,
left: *AST::AstNode,
bp: i64
) *AST::AstNode
Parses a primary expression: integer, float, string, char, or bool literal or an identifier. String/char literals are unescaped here.
#returns_ownership
primary -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses a prefix unary expression (-, +, !, ~, ++, --).
#returns_ownership
unary -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses a parenthesized ( ... ) grouping expression.
#returns_ownership
group -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses an array literal [elem, ...] into an array node.
#returns_ownership
array -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses *object into a dereference node.
#returns_ownership
deref -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses &object into an address-of node.
#returns_ownership
addr -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses __alloc__(size) into an allocation node.
#returns_ownership
_alloc -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses __free__(ptr) into a deallocation node.
#returns_ownership
_free -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses __cast__<Type>(expr) into a cast node.
#returns_ownership
_cast -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses __input__<Type>(msg) into an input node.
#returns_ownership
_input -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses __system__(cmd) into a system-command node.
#returns_ownership
_system -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses __syscall__(arg, ...) into a syscall node.
#returns_ownership
syscall -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses __sizeof__<Type> into a sizeof node.
#returns_ownership
_sizeof -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses an anonymous struct literal { name: value, ... } (struct name and
alias null) into a struct-expression node.
#returns_ownership
estruct -> fn(
p: *PARS::Parser
) *AST::AstNode
Parses left[expr] into an index node.
#returns_ownership
index -> fn(
p: *PARS::Parser
) *AST::AstNode