MiSawa / xq

Pure rust implementation of jq
MIT License
318 stars 18 forks source link

Binding variable after comma operator does not work #53

Closed itchyny closed 2 years ago

itchyny commented 2 years ago
❯ jq -n '[1, 2 as $x | $x + 1]'
[
  1,
  3
]

❯ xq -n '[1, 2 as $x | $x + 1]'
Error: compile query

Caused by:
    ParseError(UnrecognizedToken(Loc { line: 0, col: 6, byte_idx: 6 }, "Keyword(\"as\", As)", ["\"!=\"", "\"%\"", "\"%=\"", "\")\"", "\"*\"", "\"*=\"", "\"+\"", "\"+=\"", "\",\"", "\"-\"", "\"-=\"", "\"/\"", "\"//\"", "\"//=\"", "\"/=\"", "\":\"", "\";\"", "\"<\"", "\"<=\"", "\"=\"", "\"==\"", "\">\"", "\">=\"", "\"]\"", "\"and\"", "\"catch\"", "\"elif\"", "\"else\"", "\"end\"", "\"or\"", "\"then\"", "\"|\"", "\"|=\"", "InterpolationEnd"]))

❯ xq --version
xq 0.1.9-dcd6c4a024b54b3b2d0dc7ed90a349d42c11aa67

This looks like a regression due to switching to lalrpop.

❯ xq -n '[1, 2 as $x | $x + 1]'
[
  1,
  3
]

❯ xq --version
xq 0.1.9-95558180fabd53143a91d72e226780939461f8c5
MiSawa commented 2 years ago

Ah good catch! I actually knew that label, def and binding patterns are no longer be in a child of operators and ignore it since it complicates the grammar definition a lot, but yeah looks like I should've implemented it.

MiSawa commented 2 years ago

Hmmmmmm handling try . as $a in lalrpop would be further difficult. It may be easier to make lexer insert markers at the end of the scope of label, def and ... as ..., and maybe try (without catch)....