summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-08-02 18:31:31 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-08-02 18:31:31 -0700
commit894c655f0214531ad7eff3d68d72792ae18d40cd (patch)
treec7da31229ce40626fa937de8e688ac645ace2309 /match.c
parent73a7ae605d364be49dc5bd1cc15c1116fe47a446 (diff)
downloadtxr-894c655f0214531ad7eff3d68d72792ae18d40cd.tar.gz
txr-894c655f0214531ad7eff3d68d72792ae18d40cd.tar.bz2
txr-894c655f0214531ad7eff3d68d72792ae18d40cd.zip
Big switch to reentrant lexing and parsing.
* parser.l (YY_INPUT): Stop relying on removed yyin_stream; refer to stream via yyextra. (yyin_stream, lineno, errors, spec_file_str, prepared_error_message): Global variables removed. (yyget_column, yyset_column): Missing prototypes not generated by flex in bison bridge mode have to be added by us to avoid warning. (yyerror): Takes parser and scanner as parameters. Prepared error message is now in the parser context. Calls to other error handling functions receive scanner context. (yyerr): New function. (yyerrorf, yyerrprepf): Takes scanner argument, chases extra data to get to parser, and refers to parser variables instead of globals. (num_esc): Scanner argument added. (%option reentrant, %option bison-bridge, %option extra-type): New flex options. (grammar): yyscanner added everywhere. (end_of_char): Takes scanner argument. (parse_init): Removed references to yyin_stream and prepared_error_message. (parse_reset): Function renamed to open_txr_file. Returns results via pointers instead of setting global variables. (regex_parse, lisp_parse): Use reentrant parser interface. * parser.y (yyerror): Prototype removed. (yylex): Prototype moved after grammar, with new arguments. (sym_helper, define_transform): Take scanner argument. (make_expr): Takes parser argument. (rlrec): New static function. (rl): Function turned into macro. (mkexp, symhlpr): New macros. (%purse-parser, %parse-param, %lex-param): New Yacc options. (grammar): Actions re-worked for reentrance. Parser and scanner contexts are passed down to helper functions, in some cases via the three new macros. The result of the parse is stored in the syntax_tree member of the parser_t structure instead of a global. The yylex function receives the scanner instance. (get_spec): Function removed. (parse): New function. * parser.h (lineno, errors, yyin_stream, spec_file_str): Declarations removed. (parser_t): New struct. (yyerr): New function declared. (yyparse, yyerror, yyerrorf, end_of_regex, end_of_char, yylex, yylex_destroy): Declarations updated.
Diffstat (limited to 'match.c')
-rw-r--r--match.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/match.c b/match.c
index 344d9039..71692d1e 100644
--- a/match.c
+++ b/match.c
@@ -3660,16 +3660,18 @@ static val v_load(match_files_ctx *c)
zero, negone),
cons(target, nil)), lit("/")));
int gc = gc_state(0);
- parse_reset(path);
- yyparse();
- yylex_destroy();
+ val stream, name;
+ parser_t parser;
+
+ open_txr_file(path, &stream, &name);
+ parse(stream, name, &parser);
gc_state(gc);
- if (errors)
+ if (parser.errors)
sem_error(specline, lit("load: errors encountered in ~s"), path, nao);
{
- val spec = get_spec();
+ val spec = parser.syntax_tree;
val result = match_files(mf_spec(*c, spec));
if (!result) {