@@ -9,20 +9,28 @@ use partiql_ast::ast;
9
9
10
10
use partiql_source_map::location::{ByteOffset, BytePosition, Location, ToLocated};
11
11
12
- use crate::parse::parse_util::{strip_query, CallSite, Attrs, Synth};
12
+ use crate::parse::parse_util::{strip_expr, strip_query, strip_query_set , CallSite, Attrs, Synth};
13
13
use crate::parse::parser_state::{ParserState, IdGenerator};
14
14
15
15
grammar<'input, 'state, Id>(input: &'input str, state: &'state mut ParserState<'input, Id>) where Id: IdGenerator;
16
16
17
17
18
- pub(crate) Query: Box <ast::Expr > = {
18
+ pub(crate) TopLevelQuery: ast::AstNode <ast::TopLevelQuery > = {
19
19
<lo:@L>
20
20
<with:WithClause?>
21
+ <query:Query>
22
+ <hi:@R> => {
23
+ state.node(ast::TopLevelQuery { with, query }, lo..hi)
24
+ }
25
+ }
26
+
27
+ Query: ast::AstNode<ast::Query> = {
28
+ <lo:@L>
21
29
<set:QuerySet>
22
30
<order_by:OrderByClause?>
23
31
<limit_offset:LimitOffsetClause>
24
32
<hi:@R> => {
25
- Box::new(ast::Expr::Query( state.node(ast::Query { with, set, order_by, limit_offset }, lo..hi) ) )
33
+ state.node(ast::Query { set, order_by, limit_offset }, lo..hi)
26
34
}
27
35
}
28
36
@@ -94,7 +102,9 @@ WithCycleClause : () = {
94
102
// - all set operations are left-associative and are thus expressed as left-self-recursive rules
95
103
96
104
QuerySet: ast::AstNode<ast::QuerySet> = {
97
- <lo:@L> <lhs:QuerySet> <setop:SetOp> <setq:SetQuantifier> <rhs:SingleQuery> <hi:@R> => {
105
+ <lo:@L> <lhs:Query> <setop:SetOp> <setq:SetQuantifier> <rhs:SingleQuery> <hi:@R> => {
106
+ let lhs = strip_query(lhs);
107
+ let rhs = strip_query_set(rhs, state, lo, hi);
98
108
let set_expr = state.node(ast::SetExpr {
99
109
setop,
100
110
setq,
@@ -133,7 +143,7 @@ SetQuantifier: ast::SetQuantifier = {
133
143
SingleQuery: ast::AstNode<ast::QuerySet> = {
134
144
<lo:@L> <expr:ExprQuery> <hi:@R> => {
135
145
match *expr {
136
- ast::Expr::Query(ast::AstNode{ node: ast::Query{with: None, set, order_by:None, limit_offset:None} , .. }) => set,
146
+ ast::Expr::Query(ast::AstNode{ node: ast::Query{set, order_by:None, limit_offset:None} , .. }) => set,
137
147
_ => state.node(ast::QuerySet::Expr( expr ), lo..hi),
138
148
}
139
149
},
@@ -907,7 +917,7 @@ ExprTerm: Synth<ast::Expr> = {
907
917
}
908
918
909
919
SubQuery: ast::Expr = {
910
- "(" <q:Query> ")" => *strip_query (q),
920
+ "(" <q:Query> ")" => *strip_expr (q),
911
921
}
912
922
913
923
SubQueryAst: ast::AstNode<ast::Expr> = {
@@ -1050,7 +1060,7 @@ FunctionCallArgs: Vec<ast::AstNode<ast::CallArg>> = {
1050
1060
// Special case subquery when it is the only sub-expression of a function call (e.g., `SELECT AVG(SELECT VALUE price FROM g AS v))... `)
1051
1061
<lo:@L> <subq:SfwQuery> <hi:@R> => {
1052
1062
let qset = state.node(ast::QuerySet::Select(Box::new(subq)), lo..hi);
1053
- let query = state.node(ast::Query{ with: None, set: qset, order_by: None, limit_offset:None }, lo..hi);
1063
+ let query = state.node(ast::Query{ set: qset, order_by: None, limit_offset:None }, lo..hi);
1054
1064
vec![state.node(ast::CallArg::Positional(Box::new(ast::Expr::Query(query))), lo..hi)]
1055
1065
},
1056
1066
}
0 commit comments