eventql_parser/
error.rs

1//! Error types for lexical analysis and parsing.
2//!
3//! This module defines the error types that can occur during tokenization
4//! and parsing of EventQL queries. All errors include position information
5//! (line and column numbers) to help diagnose issues in query strings.
6
7use crate::token::Symbol;
8use thiserror::Error;
9
10/// Top-level error type for the EventQL parser.
11///
12/// This enum wraps both lexer and parser errors, providing a unified
13/// error type for the entire parsing pipeline.
14#[derive(Debug, Error)]
15pub enum Error {
16    /// Error during lexical analysis (tokenization).
17    #[error(transparent)]
18    Lexer(LexerError),
19
20    /// Error during syntactic analysis (parsing).
21    #[error(transparent)]
22    Parser(ParserError),
23}
24
25/// Errors that can occur during lexical analysis.
26///
27/// These errors are produced by the tokenizer when the input string
28/// contains invalid characters or ends unexpectedly.
29#[derive(Debug, Error)]
30pub enum LexerError {
31    /// The input ended unexpectedly while parsing a token.
32    ///
33    /// This typically occurs when a string literal or other multi-character
34    /// token is not properly closed.
35    #[error("unexpected end of input")]
36    IncompleteInput,
37
38    /// An invalid character was encountered at the specified position.
39    ///
40    /// The tuple contains `(line_number, column_number)`.
41    #[error("{0}:{1}: invalid character")]
42    InvalidSymbol(u32, u32),
43}
44
45/// Errors that can occur during syntactic analysis.
46///
47/// These errors are produced by the parser when the token sequence
48/// does not match the expected grammar of EventQL.
49#[derive(Debug, Error)]
50pub enum ParserError {
51    /// Expected an identifier but found something else.
52    ///
53    /// Fields: `(line, column, found_token)`
54    #[error("{0}:{1}: expected identifier but got {2}")]
55    ExpectedIdent(u32, u32, String),
56
57    /// Expected a specific keyword but found something else.
58    ///
59    /// Fields: `(line, column, expected_keyword, found_token)`
60    #[error("{0}:{1}: expected keyword {2} but got {3}")]
61    ExpectedKeyword(u32, u32, &'static str, String),
62
63    /// Expected a specific symbol but found something else.
64    ///
65    /// Fields: `(line, column, expected_symbol, found_token)`
66    /// ```
67    #[error("{0}:{1}: expected {2} but got {3}")]
68    ExpectedSymbol(u32, u32, Symbol, String),
69
70    /// An unexpected token was encountered.
71    ///
72    /// Fields: `(line, column, found_token)`
73    ///
74    /// This is a general error for tokens that don't fit the current parse context.
75    #[error("{0}:{1}: unexpected token {2}")]
76    UnexpectedToken(u32, u32, String),
77
78    /// The input ended unexpectedly while parsing.
79    ///
80    /// This occurs when the parser expects more tokens but encounters
81    /// the end of the token stream.
82    #[error("unexpected end of file")]
83    UnexpectedEof,
84}