rl_lang/parser/expressions/mod.rs
1//! Precedence-climbing expression parser.
2//!
3//! Expressions are parsed via a hand-written recursive-descent chain that
4//! encodes operator precedence through the call stack. From lowest to highest:
5//!
6//! ```text
7//! parse_expression (entry point, delegates to equality)
8//! |- parse_logical (and or)
9//! |- parse_equality (== !=)
10//! |- parse_comparison (< <= > >= += -= *= /=)
11//! |- parse_term (+ -)
12//! |- parse_factor (* /)
13//! |- parse_unary (! -)
14//! |- parse_primary (literals, identifiers, calls, lambdas, …)
15//! |- parse_postfix (. method chains)
16//! ```
17//!
18//! Every function returns an [`Expression`] node with its source [`Span`] set
19//! to the full extent of the sub-expression it consumed.
20
21mod comparsion;
22mod equality;
23mod factor;
24mod logical;
25mod postfix;
26mod primary;
27mod struct_literal;
28mod term;
29mod unary;
30
31use crate::{ast::ExprId, parser::parser_logic::Parser, utils::errors::Error};
32
33impl Parser {
34 /// Entry point for expression parsing. Delegates to [`parse_equality`].
35 ///
36 /// [`parse_equality`]: Parser::parse_equality
37 pub fn parse_expression(&mut self) -> Result<ExprId, Error> {
38 self.parse_logical()
39 }
40}