1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
mod error;
mod lexer;
mod parse;
mod preprocessor;
mod token_parser;
use parse::parse_partiql;
use partiql_ast::ast;
use partiql_source_map::line_offset_tracker::LineOffsetTracker;
use partiql_source_map::location::BytePosition;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub type LexicalError<'input> = error::LexError<'input>;
pub type ParseError<'input> = error::ParseError<'input, BytePosition>;
pub type ParserResult<'input> = Result<Parsed<'input>, ParserError<'input>>;
#[non_exhaustive]
#[derive(Debug, Default)]
pub struct Parser {}
impl Parser {
pub fn parse<'input>(&self, text: &'input str) -> ParserResult<'input> {
let mut offsets = LineOffsetTracker::default();
match parse_partiql(text, &mut offsets) {
Ok(ast) => Ok(Parsed { text, offsets, ast }),
Err(errors) => Err(ParserError {
text,
offsets,
errors,
}),
}
}
}
#[non_exhaustive]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(dead_code)]
pub struct Parsed<'input> {
pub text: &'input str,
pub offsets: LineOffsetTracker,
pub ast: Box<ast::Expr>,
}
#[non_exhaustive]
#[allow(dead_code)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ParserError<'input> {
pub text: &'input str,
pub offsets: LineOffsetTracker,
pub errors: Vec<ParseError<'input>>,
}