haskell-jsonnet icon indicating copy to clipboard operation
haskell-jsonnet copied to clipboard

Comprehensions can't handle chained `ifspec`s

Open ozkutuk opened this issue 4 years ago • 1 comments

Minimal way to reproduce

$ cabal run hs-jsonnet -- -e '[x for x in [1,2,3] if x > 1 if x < 3]'
1:30:
  |
1 | [x for x in [1,2,3] if x > 1 if x < 3]
  |                              ^
unexpected 'i'
expecting "!=", "&&", "<<", "<=", "==", ">=", ">>", "for", "in", "||", '%', '&', '(', '*', '+', '-', '/', '<', '>', '[', ']', '^', '|', ., or object

Expected output

$ jsonnet -e '[x for x in [1,2,3] if x > 1 if x < 3]'
[
   2
]

The problem

In our implementation, the ifspecs are parsed as an optional part of forspecs. This only allows a singular ifspec to be allowed per forspec. However, the Jsonnet specification allows an array comprehension to contain any number of compspecs after an initial mandatory forspec, where compspecs can be either forspecs or ifspecs.

ozkutuk avatar Jan 15 '22 08:01 ozkutuk

Thanks for reporting! We can have nested forspecs, as done here, but the way we are doing it now, the ifspec is optional and goes attached to the forspec. I guess we could change that so that to have a list of ifspecs. The way I implemented this is a bit different from how it's specified.

std.assertEqual(obj, { ["f" + x + y + z]: { x: x, y: y, z: z } for x in [1, 2, 3] for y in [1, 4, 6] if x + 2 < y for z in [true, false] })

moleike avatar Jan 21 '22 16:01 moleike