sql_cli/sql/parser/expressions/
mod.rs

1// Expression parsing module
2// This module contains all expression parsing logic extracted from the main parser
3
4use crate::sql::parser::ast::SqlExpression;
5use crate::sql::parser::lexer::Token;
6use tracing::{debug, trace};
7
8pub mod arithmetic;
9pub mod case;
10pub mod comparison;
11pub mod logical;
12pub mod primary;
13
14/// Trait for expression parsers
15/// This allows us to modularize expression parsing while maintaining consistency
16pub trait ExpressionParser {
17    /// Get the current token
18    fn current_token(&self) -> &Token;
19
20    /// Advance to the next token
21    fn advance(&mut self);
22
23    /// Peek at the next token without consuming it
24    fn peek(&self) -> Option<&Token>;
25
26    /// Check if we're at the end of input
27    fn is_at_end(&self) -> bool;
28
29    /// Consume a specific token or return error
30    fn consume(&mut self, expected: Token) -> Result<(), String>;
31
32    /// Parse an identifier and return its name
33    fn parse_identifier(&mut self) -> Result<String, String>;
34}
35
36/// Helper function to log expression parsing decisions
37#[inline]
38pub fn log_parse_decision(context: &str, token: &Token, decision: &str) {
39    debug!(
40        context = context,
41        token = ?token,
42        decision = decision,
43        "Parser decision point"
44    );
45}
46
47/// Helper function for detailed trace logging
48#[inline]
49pub fn trace_parse_entry(function: &str, token: &Token) {
50    trace!(
51        function = function,
52        token = ?token,
53        "Entering parse function"
54    );
55}
56
57/// Helper function for trace exit logging
58#[inline]
59pub fn trace_parse_exit(function: &str, result: &Result<SqlExpression, String>) {
60    trace!(
61        function = function,
62        success = result.is_ok(),
63        "Exiting parse function"
64    );
65}