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

Comprehensions can't handle chained ifspecs #46

Open
ozkutuk opened this issue Jan 15, 2022 · 1 comment
Open

Comprehensions can't handle chained ifspecs #46

ozkutuk opened this issue Jan 15, 2022 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ozkutuk
Copy link
Contributor

ozkutuk commented Jan 15, 2022

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.

@moleike moleike added the bug Something isn't working label Jan 15, 2022
@moleike
Copy link
Owner

moleike commented Jan 21, 2022

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 moleike added the help wanted Extra attention is needed label Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants