Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Lezer grammar): Fix support for ranges #3549

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions grammars/prql-lezer/src/prql.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Assign_call { ident_part "=" expr_call }
Case_branch { Expr "=>" Expr }
Array { "[" newline* Expr (("," newline* ) Expr)* ","? newline* "]" }
// Possibly we could only accept case branches inside the Tuple?
Case { @specialize<ident_part, "case"> Tuple }
Case { @specialize<ident_part, "case"> Tuple }

Nested_pipeline { "(" newline* Pipeline ~ambig_newline newline? ")" }

Expand All @@ -53,13 +53,13 @@ Ident { ident_part ( "." (ident_part | "*"))* }
Op_bin { op_bin_only | !term op_unary }

@tokens {
Date { @digit+ "-" @digit+ "-" @digit+ }
Time { @digit+ ":" @digit+ ( ":" @digit+ ( "." @digit+ )? )? }
date { @digit+ "-" @digit+ "-" @digit+ }
time { @digit+ ":" @digit+ ( ":" @digit+ ( "." @digit+ )? )? }
// We can't seem to set the number of digits, so this will allow any
// combination of digits & hyphens.
// TODO: does excluding spaces here work? It seems to make a difference, but
// then I think the `Number` rule doesn't allow spaces...
DateTime { "@" ![ ] ( Date | Time | Date "T" Time ( "Z" | ( "-" | "+" ) @digit+ ":" @digit+ )? ) }
DateTime { "@" ![ ] ( date | time | date "T" time ( "Z" | ( "-" | "+" ) @digit+ ":" @digit+ )? ) }
vanillajonathan marked this conversation as resolved.
Show resolved Hide resolved
identifier_char { @asciiLetter | $[_\u{a1}-\u{10ffff}] }
ident_part { identifier_char (identifier_char | "_" | @digit )* }
// TODO: This is not as precise as PRQL, which doesn't allow trailing
Expand All @@ -74,7 +74,9 @@ Op_bin { op_bin_only | !term op_unary }
line_wrap { "\\" }
wrapped_line { newline+ (Comment newline+)* line_wrap }
newline { "\n" }
Range { ".." }
// TODO: Because this can also be used to compile to BETWEEN, ranges should
// allow any literal, and arguably any expression. And if possible it shouldn't allow for spaces.
Range { @digit+ ".." @digit+ }
vanillajonathan marked this conversation as resolved.
Show resolved Hide resolved
vanillajonathan marked this conversation as resolved.
Show resolved Hide resolved
// Couldn't managed to do these & the interpolated as a template; couldn't
// find how to negate a variable template
String { $["] !["]* $["] | $['] ![']* $['] }
Expand All @@ -96,9 +98,11 @@ Op_bin { op_bin_only | !term op_unary }
F_string {Interpolated_string<'f'>}

// We need to give precedence to `Op_bin` so we don't get `x+y` as `x` & `+y`.
// S & F strings have precedence over idents beginning with s / f (we could
// R, S & F strings have precedence over idents beginning with r / s / f (we could
// use specialize but I think means we need to redefine `String` for each)
@precedence { R_string, S_string, F_string, op_bin_only, ident_part }

@precedence { Range, Number }
}

Def { @specialize<ident_part, "let"> ident_part "=" (Nested_pipeline (newline+ | end) | Lambda) }
Expand Down
7 changes: 7 additions & 0 deletions grammars/prql-lezer/test/misc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 10..20

10..20

==>

Query(Statements(Pipeline_stmt(Pipeline(Expr(Range)))))