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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright Amazon.com, Inc. or its affiliates.
//! Provides a parser for the [PartiQL][partiql] query language.
//!
//! # Usage
//!
//! ```
//! use std::fmt;
//! use std::fmt::Formatter;
//! use itertools::Itertools;
//! use partiql_common::syntax::location::LineAndColumn;
//! use partiql_parser::{Parser, ParserError, ParserResult};
//!
//! let parser = Parser::default();
//!
//! let parsed = parser.parse("SELECT g FROM data GROUP BY a").expect("successful parse");
//!
//! let errs: ParserError = parser.parse("SELECT").expect_err("expected error");
//!
//! // Print out messages with byte offsets
//! let errs_at: ParserError =
//! parser.parse("SELECT * FROM a AY a CROSS JOIN c AS c AT q").unwrap_err();
//! assert_eq!(errs_at.errors[0].to_string(), "Unexpected token `<a:UNQUOTED_IDENT>` at `(b19..b20)`");
//!
//! // Print out messages with line:column offsets
//! let errs_at_nice: ParserError =
//! parser.parse("SELECT * FROM a AY a CROSS JOIN c AS c AT q").unwrap_err();
//! let offsets = &errs_at_nice.offsets;
//! let source = &errs_at_nice.text;
//! let err_msg = errs_at_nice.errors.iter().map(|e|
//! e.clone().map_loc(|loc| LineAndColumn::from(offsets.at(source, loc).unwrap()).to_string())).join("\n");
//! assert_eq!(err_msg, "Unexpected token `<a:UNQUOTED_IDENT>` at `(1:20..1:21)`");
//!
//!
//!
//! // Print out messages with custom line:column offsets
//! #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
//! pub struct VerboseLineAndColumn(LineAndColumn);
//!
//! impl fmt::Display for VerboseLineAndColumn {
//! fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
//! write!(f, "Line {}, Offset {}", self.0.line, self.0.column)
//! }
//! }
//!
//! let err_msg = errs_at_nice.errors.iter().map(|e|
//! e.clone().map_loc(|loc| VerboseLineAndColumn(LineAndColumn::from(offsets.at(source, loc).unwrap())).to_string())).join("\n");
//! assert_eq!(err_msg, "Unexpected token `<a:UNQUOTED_IDENT>` at `(Line 1, Offset 20..Line 1, Offset 21)`");
//! ```
//!
//! [partiql]: https://partiql.org
use ;
use ast;
use LineOffsetTracker;
use BytePosition;
use LocationMap;
use ;
/// [`std::error::Error`] type for errors in the lexical structure for the `PartiQL` parser.
pub type LexicalError<'input> = LexError;
/// [`std::error::Error`] type for errors in the syntactic structure for the `PartiQL` parser.
pub type ParseError<'input> = ParseError;
/// General [`Result`] type for the `PartiQL` [`Parser`].
pub type ParserResult<'input> = ;
/// A `PartiQL` parser from statement strings to AST.
/// The output of parsing `PartiQL` statement strings: an AST and auxiliary data.
/// The output of errors when parsing `PartiQL` statement strings: an errors and auxiliary data.