01mf02 / jaq

A jq clone focussed on correctness, speed, and simplicity
MIT License
2.61k stars 63 forks source link

Discrepancy with jq and gojq: subfunction after variable declaration #157

Open pkoppstein opened 5 months ago

pkoppstein commented 5 months ago

Using jaq.jq below:

$ jq -n -f jaq.jq
1
2

$ goq -n -f jaq.jq
1
2

$ jaq -n -f jaq.jq
Error: Unexpected token while parsing definition, expected [, if, try, {, .., -, ., (, "
   ╭─[<unknown>:5:5]
   │
 5 │   | def a: 2 * $s;
   │     ──┬─  
   │       ╰─── Unexpected token def
───╯

jaq.jq

def example:
  . as $s
  | def a: 2 * $s;
  ($s, a);

1 | example
01mf02 commented 1 month ago

Thanks a lot for reporting this, @pkoppstein! I was not aware that definitions were allowed at such positions. Supporting this will require a breaking change to the syntax, so my plan is to support this for 2.0.