Skip to main content

linkrs_query/parser/parsing/
stmt_parser.rs

1//! Sentence Parsing Module
2//!
3//! Responsible for parsing various statements, including MATCH, GO, CREATE, DELETE, UPDATE, etc.
4//! This module serves as an entry point; it delegates the specific analysis logic to the various sub-modules.
5
6mod admin;
7mod database;
8mod dispatch;
9mod group_by;
10mod misc;
11mod pipe;
12
13#[cfg(test)]
14mod tests;
15
16use crate::parser::ast::stmt::*;
17use crate::parser::core::error::ParseError;
18use crate::parser::parsing::parse_context::ParseContext;
19
20/// Statement parser - namespace for statement parsing functions.
21pub struct StmtParser;
22
23impl StmtParser {
24    /// Parse statements (pipeline operators are supported).
25    pub fn parse_statement(ctx: &mut ParseContext) -> Result<Stmt, ParseError> {
26        let stmt = Self::parse_single_statement(ctx)?;
27        pipe::parse_pipe_suffix(ctx, stmt)
28    }
29
30    /// Analyzing a single statement (without distributing it through any pipelines)
31    fn parse_single_statement(ctx: &mut ParseContext) -> Result<Stmt, ParseError> {
32        if let Some(result) = dispatch::parse_keyword_statement(ctx) {
33            return result;
34        }
35        dispatch::parse_token_statement(ctx)
36    }
37}