Skip to content

Commit 6c18fb5

Browse files
authored
[bugfix] Fix bug in parsing PathExpr steps (#162)
Without this change PathExpr steps only has the root and let step in the steps. See the related issue for more details. The bug has surfaced after #152 merged.
1 parent 033ad63 commit 6c18fb5

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

partiql-parser/src/parse/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ mod tests {
283283
parse!(r#"@a.b[*]"#);
284284
parse!(r#"@"a".b[*]"#);
285285
parse!(r#"tables.items[*].product.*.nest"#);
286+
parse!(r#"a.b.c['item']."d"[5].e['s'].f[1+2]"#);
286287
}
287288

288289
#[test]
@@ -322,6 +323,33 @@ mod tests {
322323
parse!(r#"foo(x, y)[*].*.b[5]"#);
323324
}
324325

326+
#[test]
327+
fn test_pathexpr_struct() {
328+
let res = parse!(r#"a.b.c['item']."d"[5].e['s'].f[1+2]"#);
329+
330+
if let ast::ExprKind::Query(ast::AstNode {
331+
node:
332+
ast::Query {
333+
set:
334+
ast::AstNode {
335+
node: ast::QuerySet::Expr(ref e),
336+
..
337+
},
338+
..
339+
},
340+
..
341+
}) = res.kind
342+
{
343+
if let ast::ExprKind::Path(p) = &e.kind {
344+
assert_eq!(9, p.node.steps.len())
345+
} else {
346+
panic!("PathExpr test failed!");
347+
}
348+
} else {
349+
panic!("PathExpr test failed!");
350+
}
351+
}
352+
325353
#[test]
326354
#[should_panic]
327355
fn erroneous() {

partiql-parser/src/parse/partiql.lalrpop

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -964,21 +964,21 @@ FunctionArgName: ast::SymbolPrimitive = {
964964
// See the path expression conformance tests under `partiql-tests` or parser unit-tests for more examples.
965965
PathSteps: Vec<ast::PathStep> = {
966966
<path:PathSteps> "." <v:PathExprVarRef> => {
967-
vec![ast::PathStep::PathExpr( ast::PathExpr{ index: Box::new(v) })]
967+
let mut steps = path;
968+
steps.push(ast::PathStep::PathExpr( ast::PathExpr{ index: Box::new(v) }));
969+
steps
968970
},
969971
<lo:@L> <path:PathSteps> "[" "*" "]" <hi:@R> => {
970-
vec![ast::PathStep::PathWildCard]
972+
let mut steps = path;
973+
steps.push(ast::PathStep::PathWildCard);
974+
steps
971975
},
972976
<lo:@L> <path:PathSteps> "." "*" <hi:@R> => {
973-
let step = ast::PathStep::PathUnpivot;
974-
975977
let mut steps = path;
976-
steps.push(step);
978+
steps.push(ast::PathStep::PathUnpivot);
977979
steps
978980
// ast::Path{ root:path.root, steps }
979981
},
980-
// TODO Add path expression with CAST E.g. {'attr': 1, 'b':2}[CAST('at' || 'tr' AS STRING)]
981-
// once https://github.com/partiql/partiql-lang-rust/pull/122 is merged
982982
<lo:@L> <path:PathSteps> "[" <expr:ExprQuery> "]" <hi:@R> => {
983983
let step = ast::PathStep::PathExpr(
984984
ast::PathExpr{

0 commit comments

Comments
 (0)