helix_db/helixc/parser/
parser_methods.rs1use super::helix_parser::Rule;
2use core::fmt;
3
4pub trait Parser {
5 fn parse(&self, input: &str) -> Result<(), String>;
6}
7
8
9pub enum ParserError {
10 ParseError(String),
11 LexError(String),
12 ParamDoesNotMatchSchema(String)
13}
14
15impl fmt::Display for ParserError {
16 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17 match self {
18 ParserError::ParseError(e) => write!(f, "Parse error: {}", e),
19 ParserError::LexError(e) => write!(f, "Lex error: {}", e),
20 ParserError::ParamDoesNotMatchSchema(p) => write!(f, "Parameter with name: {} does not exist in the schema", p),
21 }
22 }
23}
24
25impl From<pest::error::Error<Rule>> for ParserError {
26 fn from(e: pest::error::Error<Rule>) -> Self {
27 ParserError::ParseError(e.to_string())
28 }
29}
30
31impl From<String> for ParserError {
32 fn from(e: String) -> Self {
33 ParserError::LexError(e)
34 }
35}
36
37impl From<&'static str> for ParserError {
38 fn from(e: &'static str) -> Self {
39 ParserError::LexError(e.to_string())
40 }
41}
42
43
44impl std::fmt::Debug for ParserError {
45 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46 match self {
47 ParserError::ParseError(e) => write!(f, "Parse error: {}", e),
48 ParserError::LexError(e) => write!(f, "Lex error: {}", e),
49 ParserError::ParamDoesNotMatchSchema(p) => write!(f, "Parameter with name: {} does not exist in the schema", p),
50 }
51 }
52}