1#![deny(rust_2018_idioms)]
2#![deny(clippy::all)]
3mod error;
26mod lexer;
27mod parse;
28mod preprocessor;
29mod token_parser;
30
31use parse::{parse_partiql, AstData, ErrorData};
32use partiql_ast::ast;
33use partiql_common::syntax::line_offset_tracker::LineOffsetTracker;
34use partiql_common::syntax::location::BytePosition;
35use partiql_common::syntax::metadata::LocationMap;
36#[cfg(feature = "serde")]
37use serde::{Deserialize, Serialize};
38
39pub type LexicalError<'input> = error::LexError<'input>;
41
42pub type ParseError<'input> = error::ParseError<'input, BytePosition>;
44
45pub type ParserResult<'input> = Result<Parsed<'input>, ParserError<'input>>;
47
48#[non_exhaustive]
50#[derive(Debug, Default)]
51pub struct Parser {}
52
53impl Parser {
54 pub fn parse<'input>(&self, text: &'input str) -> ParserResult<'input> {
56 match parse_partiql(text) {
57 Ok(AstData {
58 ast,
59 locations,
60 offsets,
61 }) => Ok(Parsed {
62 text,
63 offsets,
64 ast,
65 locations,
66 }),
67 Err(ErrorData { errors, offsets }) => Err(ParserError {
68 text,
69 offsets,
70 errors,
71 }),
72 }
73 }
74}
75
76#[non_exhaustive]
78#[derive(Debug)]
79#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
80#[allow(dead_code)]
81pub struct Parsed<'input> {
82 pub text: &'input str,
83 pub offsets: LineOffsetTracker,
84 pub ast: ast::AstNode<ast::TopLevelQuery>,
85 pub locations: LocationMap,
86}
87
88#[non_exhaustive]
90#[allow(dead_code)]
91#[derive(Debug)]
92#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
93pub struct ParserError<'input> {
94 pub text: &'input str,
95 pub offsets: LineOffsetTracker,
96 pub errors: Vec<ParseError<'input>>,
97}