diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-27 06:51:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-27 06:51:23 -0700 |
commit | 2f8bbbb5e50b0297bd531da3388589716a8cf0f2 (patch) | |
tree | 13161ca135e5cdcfa37a5d50004251c0dc4e00bd /debug.h | |
parent | 77bc5d4cb9e364a56835fa46226e50faa422fe45 (diff) | |
download | txr-2f8bbbb5e50b0297bd531da3388589716a8cf0f2.tar.gz txr-2f8bbbb5e50b0297bd531da3388589716a8cf0f2.tar.bz2 txr-2f8bbbb5e50b0297bd531da3388589716a8cf0f2.zip |
json: support quasiquoting.
* parser.h (end_of_json_unquote): Declared.
* parser.l (JPUNC, NJPUNC): Add ~ and * characters to set of
JSON punctuators.
(grammar): Allow closing brace character in NESTED, SPECIAL
and QSPECIAL statues to be a token. This is because it occurs
as a lookahead character in this situation #J{"foo":~expr}.
The lexer switches from the JSON to the NESTED start state
when it scans the ~ token, so that expr is treated as Lisp.
But then } is consumed as a lookahead token by the parser in
that same mode; when we pop back to JSON mode, the } token has
already been scanned in NESTED mode.
We add two new rules in JSON mode to the lexer to recognize
the ~ unquote and ~* splicing unquote. Both have to push the
NESTED start condition.
(end_of_json_unquote): New function.
* parser.y (JSPLICE): New token.
(json_val): Logic for unquoting. The array and hash rules must
now be prepared to deal with json_vals and json_pairs now
producing a list object instead of a hash or vector. That is
the signal that the data contains active quasiquotes and must
be translated to the special literal syntax for quasiquoted
vectors and hashes. Here we also add the rules for ~ and ~*
unquoting syntax, including managing the lexer's transition
back to the JSON start condition.
(json_vals, json_pairs): We add the logic here to recognize
unquotes in quasiquoting state. This is more clever than the
way it is done in the Lisp areas of the grammar. If no
quasiquotes occur, we construct a vector or hash,
respectively, and add to it. If unquotes occur and if we
are nested in a quasiquote, we switch the object to a list,
and continue it that way.
(yybadtoken): Handle JSPLICE.
* lex.yy.c.shipped, y.tab.c.shipped, y.tab.h.shipped: Updated.
Diffstat (limited to 'debug.h')
0 files changed, 0 insertions, 0 deletions