-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lex $foo as a single token, instead of using '$' IDENT #2681
Conversation
We still need |
I've only only renamed |
LGTM. Anyone else want to chime in before we merge this? |
LGMT. But could include some tests? |
What would a test here be, that |
I mostly was thinking of that keywords can now be used as binding, the whitespace thing might not be as important to test? So maybe something like:
|
I added some tests |
4c139f8
to
2a7b623
Compare
Previously, bindings were parsed as the combination of two tokens: '$' IDENT This meant that using a keyword as variable name (e.g. $then, $label) did not work. Attempts were made to allow $keyword to work by adding some '$' Keyword rules in the parser, but this did not allow $keyword in all places: jq --arg label foo -n '$label' # ok jq -n '"foo" as $label | .' # error Treating $foo as a single token is much simpler, in my opinion. This patch also changes how LOC is lexed: "$__loc__" instead of as "__loc__" that gets combined with '$' in the parser. This patch also disallows having spaces after '$' when recalling a variable `$ foo' since that was probably just an unintentional side effect of the implementation, and it was not documented. Fixes jqlang#2675
Thanks! |
Previously, variable/symbols were parsed as the combination of two tokens: '$' IDENT
This meant that using a keyword as variable name (e.g. $then, $label) did not work.
Attempts were made to allow $keyword to work by adding some '$' Keyword rules in the parser, but this did not allow $keyword in all places:
jq --arg label foo -n '$label' # ok
jq -n '"foo" as $label | .' # error
Treating $foo as a single token is much simpler, in my opinion.
This patch also changes how LOC is lexed: "$loc" instead of as "loc" that gets combined with '$' in the parser.
This patch also disallows having spaces after '$' when recalling a variable `$ foo' since that was probably just an unintentional side effect of the implementation, and it was not documented.
Fixes #2675 and fixes #526.