summaryrefslogtreecommitdiffstats
path: root/parser.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-26 22:48:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-26 22:48:52 -0700
commit2df469c3cda02c07f17e65cdaae5d9d16dc6b978 (patch)
treeba88b0ceff362bf8f544fbac9bd389eda7da486a /parser.h
parent644a28827acc238aefcd907820eed3378d41e3eb (diff)
downloadtxr-2df469c3cda02c07f17e65cdaae5d9d16dc6b978.tar.gz
txr-2df469c3cda02c07f17e65cdaae5d9d16dc6b978.tar.bz2
txr-2df469c3cda02c07f17e65cdaae5d9d16dc6b978.zip
New #J syntax for JSON objects in TXR Lisp.
(needs buffer literal error message cleanup) * parser.c (json_s): New symbol variable. (is_balanced_line): Follow braces out of initial state. This concession allows the listener to accept input like #J{"a":"b"}. (me_json): New static function (macro expander). The #J X syntax produces a (json Y) form, with the JSON syntax X translated to a Lisp object Y. If that is evaluated, this macro translates it to (quote Y). (parse_init): initialize json_s variable with interned symbol, and register the json macro. * parser.h (json_s): Declared. (end_of_json): Declared. * parser.l (num_esc): Treat u escape sequences in the same way as x. This function can then be used for handling the \u escapes in JSON string literals. (DIG19, JNUM, JPUNC, NJPUNC): New lex named patterns. (JSON, JLIT): New lex start conditions. (grammar): Recognize #J syntax, mapping to HASH_J token, which transitions into JSON start state. In JSON start state, handle all the elements: numbers, keywords, arrays and objects. Transition into JLIT state. In JLIT start state, handle all the elements of JSON string literals, including surrogate pair escapes. JSON literals share the fallback {UANY} fallback patter with other literals. (end_of_jason): New function. * parser.y (HASH_J, JSKW): New token symbols. (json, json_val, json_vals, json_pairs): New nonterminal symbols, and rules. (i_expr, n_expr): Generate json nonterminal, to hook the stuff into the grammar. (yybadtoken): Handle JKSW and HASH_J tokens. * lex.yy.c.shipped, y.tab.c.shipped, y.tab.h.shipped: Updated.
Diffstat (limited to 'parser.h')
-rw-r--r--parser.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/parser.h b/parser.h
index d27ba0f9..851e62ff 100644
--- a/parser.h
+++ b/parser.h
@@ -75,6 +75,7 @@ extern const wchar_t *spec_file;
extern val form_to_ln_hash;
extern val parser_s, unique_s, circref_s;
extern val rec_source_loc_s;
+extern val json_s;
void yydebug_onoff(int);
void yyerror(scanner_t *scanner, parser_t *, const char *s);
void yyerr(scanner_t *scanner, const char *s);
@@ -83,6 +84,7 @@ void yybadtoken(parser_t *, int tok, val context);
void end_of_regex(scanner_t *scanner);
void end_of_char(scanner_t *scanner);
void end_of_buflit(scanner_t *scanner);
+void end_of_json(scanner_t *scanner);
#ifdef SPACE
int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner);
#endif