diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2023-07-09 20:32:51 +0200 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2023-07-09 17:23:19 -0500 |
commit | 193f432e0849c71d8e34910ba60bdfbd94aa0ba9 (patch) | |
tree | 46566e588d3595e0fe67e65f7bcfcfcf7bb4c227 /src/lexer.l | |
parent | c08ecbaf239592018a2050b8515040d4a9f2e7aa (diff) |
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
Diffstat (limited to 'src/lexer.l')
-rw-r--r-- | src/lexer.l | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lexer.l b/src/lexer.l index e74a4dce..d29de81f 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -60,7 +60,7 @@ struct lexer_param; "catch" { return CATCH; } "label" { return LABEL; } "break" { return BREAK; } -"__loc__" { return LOC; } +"$__loc__" { return LOC; } "|=" { return SETPIPE; } "+=" { return SETPLUS; } "-=" { return SETMINUS; } @@ -122,6 +122,7 @@ struct lexer_param; ([a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]* { yylval->literal = jv_string(yytext); return IDENT;} \.[a-zA-Z_][a-zA-Z_0-9]* { yylval->literal = jv_string(yytext+1); return FIELD;} +\$([a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]* { yylval->literal = jv_string(yytext+1); return BINDING;} [ \n\t]+ {} |