summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-04-21 04:06:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-04-21 04:06:20 -0700
commit2e36e0feae8d1dd75c8410b365d7dc33b30ce66b (patch)
treedf3e255d60c16c6e320742b87379d2eb7ba8b05a /txr.c
parenteffd37e7ed64dd0300b37af1a102febea84c9504 (diff)
downloadtxr-2e36e0feae8d1dd75c8410b365d7dc33b30ce66b.tar.gz
txr-2e36e0feae8d1dd75c8410b365d7dc33b30ce66b.tar.bz2
txr-2e36e0feae8d1dd75c8410b365d7dc33b30ce66b.zip
parser: always use stream-associated parser for parse_once.
This refactoring is needed for fixing the off-by-one line number bug when the hash bang line is processed. * eval.c (load): Don't define parser locally; ensure there is one in the stream and use it. * match.c (v_load): Likewise. * parser.c (get_parser_impl): Renamed to parser_get_impl and changed from internal to external linkage. (ensure_parser): Changed to external linkage. (lisp_parser_impl, read_file_common): Follow rename of get_parser_impl. * parser.h (parse_once): Declaration updated. (parser_get_impl, ensure_parser): Declared. * parser.y (parse_once): Take self parameter; drop parser parameter. Ensure a parser to the stream, rather than declaring one locally. Don't clean up the parser when done, just let the stream clean it up. * txr.c (parse_once_noerr): Parser argument is dropped and not passed to parse_once. Program name is passed as self argument to parse_once. (txr_main): When parsing the TXR pattern query, don't define a parser locally; ensure there is one in the stream and use it, like in load and v_load.
Diffstat (limited to 'txr.c')
-rw-r--r--txr.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/txr.c b/txr.c
index 4de8c3f7..5c9ce0c6 100644
--- a/txr.c
+++ b/txr.c
@@ -470,10 +470,11 @@ static void no_dbg_support(val arg)
}
#endif
-static int parse_once_noerr(val stream, val name, parser_t *parser)
+static int parse_once_noerr(val stream, val name)
{
val pfx = format(nil, lit("~a:"), name, nao);
- ignerr_func_body(int, 0, parse_once(stream, name, parser), std_error, pfx);
+ ignerr_func_body(int, 0, parse_once(prog_string, stream, name),
+ std_error, pfx);
}
static val read_compiled_file_noerr(val self, val stream, val name, val error_stream)
@@ -1052,22 +1053,23 @@ int txr_main(int argc, char **argv)
if (!txr_lisp_p)
{
int gc = gc_state(0);
- parser_t parser;
- parse_once_noerr(parse_stream, spec_file_str, &parser);
+ val parser_obj = ensure_parser(parse_stream);
+ parser_t *parser = parser_get_impl(prog_string, parser_obj);
+ parse_once_noerr(parse_stream, spec_file_str);
gc_state(gc);
close_stream(parse_stream, nil);
uw_release_deferred_warnings();
- spec = parser.syntax_tree;
+ spec = parser->syntax_tree;
opt_loglevel = match_loglevel;
if (opt_compat && opt_compat <= 199)
reg_var(intern(lit("*self-path*"), user_package), spec_file_str);
- if (parser.errors) {
+ if (parser->errors) {
if (enter_repl)
goto repl;
return EXIT_FAILURE;