Commit Graph
4 Commits
Author SHA1 Message Date
Emanuele Torre 6ca7973d49 Allow using { $__loc__ } as shorthand for { __loc__: $__loc__ }
n.b.: { $__loc__: "foo" }  is still not allowed.

$__loc__ cannot be overwritten, and it is always an object.
Using { $x: "foo" } where $x is not a string is an error, so there is
not much of a point in supporting that.
2023-07-10 12:04:54 -05:00
Emanuele Torre 193f432e08 Lex $foo as a single token, instead of using '$' IDENT
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 #2675
2023-07-09 17:23:19 -05:00
Emanuele Torre c08ecbaf23 Mark src/{parser,lexer}.{c,h} as generated files in .gitattributes
This should hide edit to those files in PR diffs making PRs easier to
review.
2023-07-09 14:38:17 -05:00
Emanuele Torre cd8898d5b9 exit immediately after halt or halt_error is called
Instead of continuing to the next input, and only exiting if there are
no more inputs.

Closes #2533
2023-07-07 11:13:28 -05:00