Skip to content

fix: compare with 'in' operator #15

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

Merged
merged 4 commits into from
Aug 9, 2023

Conversation

Duologic
Copy link
Contributor

@Duologic Duologic commented Jul 25, 2023

Binary op "in" comparison 'string' in obj wasn't working properly, this PR adds it to the grammar.

This PR also adds test for comparison and for loops as they both deal with the 'in' keyword.

Also fixes #13 (see comments)

@aryx
Copy link

aryx commented Jul 25, 2023

cc @tjdevries

grammar.js Outdated
Comment on lines 177 to 227
//"[", $.expr, "]",
//":",
//$.expr,
$.field,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not entirely according to spec but it prevents a precedence issue for fieldnames in brackets { [fieldname]: value }. I found this when making PR #16 but solved by this change.

Comment on lines 1 to 3
=============================
Resolve expr in fieldname key
=============================
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case from #16

Comment on lines +52 to +55
{
['item' + i](v): i + v
for i in std.range(0,10)
}
Copy link
Contributor Author

@Duologic Duologic Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't possible according to the specification but is correctly intepreted by jsonnet.

// a.jsonnet
local lib = {
  ['item' + i](v): i + v
  for i in std.range(0, 10)
};

lib.item10(3)
[I] ➜ jsonnet a.jsonnet
13

[I] ➜ cjsonnet a.jsonnet
13

[I] ➜ jrsonnet a.jsonnet
13

@tjdevries
Copy link
Contributor

After you rebase, i'll take a look at this one as well. Sorry for the delay!

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Duologic
Copy link
Contributor Author

Duologic commented Aug 4, 2023

rebased

@Duologic
Copy link
Contributor Author

Duologic commented Aug 7, 2023

@tjdevries let me know if there's something I can improve

@tjdevries tjdevries merged commit 26d9699 into sourcegraph:main Aug 9, 2023
@tjdevries
Copy link
Contributor

LGTM to me! Thanks!

@Duologic Duologic deleted the in_operator_only branch August 9, 2023 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[...] as key in a map rendered as ERROR
3 participants