Skip to content

Commit 0f49d1b

Browse files
authored
Fix parsing of multiple consecutive path wildcard, unpivot, path expressions (#405)
1 parent 5629e88 commit 0f49d1b

File tree

3 files changed

+12
-37
lines changed

3 files changed

+12
-37
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Add ability to parse `ORDER BY`, `LIMIT`, `OFFSET` in children of set operators
2020

2121
### Fixes
22+
- Fixes parsing of multiple consecutive path wildcards (e.g. `a[*][*][*]`), unpivot (e.g. `a.*.*.*`), and path expressions (e.g. `a[1 + 2][3 + 4][5 + 6]`)—previously these would not parse correctly.
2223

2324
## [0.5.0] - 2023-06-06
2425
### Changed

partiql-parser/src/parse/partiql.lalrpop

+10-36
Original file line numberDiff line numberDiff line change
@@ -841,37 +841,11 @@ ExprPrecedence02: Synth<ast::Expr> = {
841841
}
842842

843843
PathExpr: ast::Path = {
844-
<l:ExprPrecedence01> "." <steps:PathSteps> => ast::Path { root:Box::new(l.data), steps },
845-
<l:ExprPrecedence01> "[" "*" "]" "." <s:PathSteps> => {
844+
<l:ExprPrecedence01> <s:PathSteps> => {
846845
let step = ast::PathStep::PathWildCard;
847846
ast::Path {
848847
root: Box::new(l.data),
849-
steps: std::iter::once(step).chain(s.into_iter()).collect()
850-
}
851-
},
852-
<l:ExprPrecedence01> "[" <expr:ExprQuery> "]" "." <s:PathSteps> => {
853-
let step = ast::PathStep::PathExpr(
854-
ast::PathExpr{
855-
index: Box::new(*expr),
856-
}
857-
);
858-
859-
ast::Path {
860-
root: Box::new(l.data),
861-
steps: std::iter::once(step).chain(s.into_iter()).collect()
862-
}
863-
},
864-
<l:ExprPrecedence01> "[" "*" "]" => ast::Path {
865-
root:Box::new(l.data), steps:vec![ast::PathStep::PathWildCard]
866-
},
867-
<l:ExprPrecedence01> "[" <expr:ExprQuery> "]" => {
868-
let step = ast::PathStep::PathExpr(
869-
ast::PathExpr{
870-
index: Box::new(*expr),
871-
});
872-
873-
ast::Path {
874-
root:Box::new(l.data), steps:vec![step]
848+
steps: s
875849
}
876850
},
877851
}
@@ -1111,9 +1085,10 @@ FunctionArgName: ast::SymbolPrimitive = {
11111085
// Examples:
11121086
// a.b
11131087
// a.*
1114-
// a.[*]
11151088
// a[*]
1089+
// a[*][*]
11161090
// a.b.c
1091+
// a[*].b[*].c
11171092
// "a".b
11181093
// "a"."b"
11191094
// { 'a': 1, 'b': 2 }.a
@@ -1137,7 +1112,6 @@ PathSteps: Vec<ast::PathStep> = {
11371112
let mut steps = path;
11381113
steps.push(ast::PathStep::PathUnpivot);
11391114
steps
1140-
// ast::Path{ root:path.root, steps }
11411115
},
11421116
<lo:@L> <path:PathSteps> "[" <expr:ExprQuery> "]" <hi:@R> => {
11431117
let step = ast::PathStep::PathExpr(
@@ -1149,17 +1123,17 @@ PathSteps: Vec<ast::PathStep> = {
11491123
steps.push(step);
11501124
steps
11511125
},
1126+
"." <v:PathExprVarRef> => {
1127+
vec![ast::PathStep::PathExpr( ast::PathExpr{ index: Box::new(v) })]
1128+
},
11521129
"[" "*" "]" => {
11531130
vec![ast::PathStep::PathWildCard]
11541131
},
1155-
"[" <expr:ExprQuery> "]" => {
1156-
vec![ast::PathStep::PathExpr( ast::PathExpr{ index: Box::new(*expr) })]
1157-
},
1158-
"*" => {
1132+
"." "*" => {
11591133
vec![ast::PathStep::PathUnpivot]
11601134
},
1161-
<v:PathExprVarRef> => {
1162-
vec![ast::PathStep::PathExpr( ast::PathExpr{ index: Box::new(v) })]
1135+
"[" <expr:ExprQuery> "]" => {
1136+
vec![ast::PathStep::PathExpr( ast::PathExpr{ index: Box::new(*expr) })]
11631137
},
11641138
}
11651139

0 commit comments

Comments
 (0)