From de547e4ec4e375531ac3d797c3e82ff2544f9464 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 7 Jun 2015 20:04:18 -0700 Subject: * match.c (v_load): Call parse_once rater than parse. * parser.c (regex_parse): Likewise. * txr.c (txr_main): Likewise. * parser.h (parse): Declaration updated. (parse_once): Declared. * parser.y (parse_once): New function, same as old parse implementation. (parse): Becomes one argument function which works with a previously initialized parser and continues the parse. --- ChangeLog | 15 +++++++++++++++ match.c | 2 +- parser.c | 4 ++-- parser.h | 3 ++- parser.y | 22 +++++++++++++++++++++- txr.c | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 466eadab..6ca77fc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2015-06-07 Kaz Kylheku + + * match.c (v_load): Call parse_once rater than parse. + + * parser.c (regex_parse, lisp_parse): Likewise. + + * txr.c (txr_main): Likewise. + + * parser.h (parse): Declaration updated. + (parse_once): Declared. + + * parser.y (parse_once): New function, same as old parse implementation. + (parse): Becomes one argument function which works with a previously + initialized parser and continues the parse. + 2015-06-07 Kaz Kylheku * stream.c (catenated_stream_p, catenated_stream_push): New functions. diff --git a/match.c b/match.c index 562e1dfd..b6d4163b 100644 --- a/match.c +++ b/match.c @@ -3725,7 +3725,7 @@ static val v_load(match_files_ctx *c) parser_t parser; open_txr_file(path, &name, &stream); - parse(stream, name, &parser); + parse_once(stream, name, &parser); gc_state(gc); if (parser.errors) diff --git a/parser.c b/parser.c index 4bed7be9..4b92cffe 100644 --- a/parser.c +++ b/parser.c @@ -111,7 +111,7 @@ val regex_parse(val string, val error_stream) { int gc = gc_state(0); val name = if3(std_error != std_null, lit("regex"), lit("")); - parse(stream, name, &parser); + parse_once(stream, name, &parser); gc_state(gc); } std_error = save_stream; @@ -145,7 +145,7 @@ val lisp_parse(val source_in, val error_stream, val error_return_val, val name_i { int gc = gc_state(0); name = if3(std_error != std_null, name, lit("")); - parse(stream, name, &parser); + parse_once(stream, name, &parser); gc_state(gc); } diff --git a/parser.h b/parser.h index 01e927fe..e1de30b2 100644 --- a/parser.h +++ b/parser.h @@ -56,7 +56,8 @@ parser_t *yyget_extra(yyscan_t scanner); void yyset_extra(parser_t *, yyscan_t); void parser_l_init(void); void open_txr_file(val spec_file, val *name, val *stream); -int parse(val stream, val name, parser_t *parser); +int parse_once(val stream, val name, parser_t *parser); +int parse(parser_t *parser); val source_loc(val form); val source_loc_str(val form); val rlset(val form, val info); diff --git a/parser.y b/parser.y index d95b3ed5..ceb1801b 100644 --- a/parser.y +++ b/parser.y @@ -1428,7 +1428,7 @@ void yybadtoken(parser_t *parser, int tok, val context) yyerrorf(scnr, lit("unexpected ~s"), chr(tok), nao); } -int parse(val stream, val name, parser_t *parser) +int parse_once(val stream, val name, parser_t *parser) { int res; yyscan_t scanner; @@ -1450,3 +1450,23 @@ int parse(val stream, val name, parser_t *parser) return res; } + +int parse(parser_t *parser) +{ + int res; + yyscan_t scanner; + + parser->errors = 0; + parser->prepared_msg = nil; + parser->syntax_tree = nil; + yylex_init(&scanner); + parser->scanner = convert(scanner_t *, scanner); + + yyset_extra(parser, parser->scanner); + + res = yyparse(parser->scanner, parser); + + yylex_destroy(parser->scanner); + + return res; +} diff --git a/txr.c b/txr.c index 03b11a89..2ba3cc40 100644 --- a/txr.c +++ b/txr.c @@ -665,7 +665,7 @@ int txr_main(int argc, char **argv) { int gc = gc_state(0); parser_t parser; - parse(parse_stream, spec_file_str, &parser); + parse_once(parse_stream, spec_file_str, &parser); gc_state(gc); if (parser.errors) -- cgit v1.2.3