From 7e13dd271df070671f9ef59969307d1bfb045ffb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 2 Jul 2015 06:13:18 -0700 Subject: Hash-bang support for .tl files. * parser.c (read_eval_stream): New boolean argument to request hash bang support. * parser.h (read_eval_stream): Declaration updated. * eval.c (sys_load): Pass new thid argument to read_eval_stream, to decline hash bang support. * match.c (v_load): Likewise. * txr.c (txr_main): Request hash bang support from read_eval_stream. Thus files referenced from the txr command line can have a #! line, which is ignored. --- ChangeLog | 18 ++++++++++++++++++ eval.c | 2 +- match.c | 2 +- parser.c | 11 ++++++++++- parser.h | 2 +- txr.c | 2 +- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5099ad37..fbb802ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2015-07-02 Kaz Kylheku + + Hash-bang support for .tl files. + + * parser.c (read_eval_stream): New boolean argument + to request hash bang support. + + * parser.h (read_eval_stream): Declaration updated. + + * eval.c (sys_load): Pass new thid argument to read_eval_stream, + to decline hash bang support. + + * match.c (v_load): Likewise. + + * txr.c (txr_main): Request hash bang support from + read_eval_stream. Thus files referenced from the txr + command line can have a #! line, which is ignored. + 2015-07-02 Kaz Kylheku Handle escapes accurately in Vim syntax highlighting. diff --git a/eval.c b/eval.c index c7cd95d8..eae9e467 100644 --- a/eval.c +++ b/eval.c @@ -2834,7 +2834,7 @@ static val sys_load(val target, val sloc) eval_error(sloc, lit("load doesn't process .txr files"), nao); } - if (!read_eval_stream(stream, std_error)) { + if (!read_eval_stream(stream, std_error, nil)) { rlset(sloc, sloc); eval_error(sloc, lit("load: ~s contains errors"), path, nao); } diff --git a/match.c b/match.c index cfb1ec2a..eeb0d079 100644 --- a/match.c +++ b/match.c @@ -3765,7 +3765,7 @@ static val v_load(match_files_ctx *c) } } } else { - if (!read_eval_stream(stream, std_error)) + if (!read_eval_stream(stream, std_error, nil)) sem_error(specline, lit("load: ~s contains errors"), path, nao); return (sym == include_s) ? nil : next_spec_k; } diff --git a/parser.c b/parser.c index 32052700..c0f3c6da 100644 --- a/parser.c +++ b/parser.c @@ -252,10 +252,19 @@ val lisp_parse(val source_in, val error_stream, val error_return_val, val name_i return pi->syntax_tree; } -val read_eval_stream(val stream, val error_stream) +val read_eval_stream(val stream, val error_stream, val hash_bang_support) { val error_val = gensym(nil); + if (hash_bang_support) { + val firstline = get_line(stream); + + if (!match_str(firstline, lit("#!"), nil)) { + val string_stream = make_string_byte_input_stream(firstline); + stream = make_catenated_stream(list(string_stream, stream, nao)); + } + } + for (;;) { val form = lisp_parse(stream, error_stream, error_val, nil); diff --git a/parser.h b/parser.h index ce276132..e6f531f2 100644 --- a/parser.h +++ b/parser.h @@ -71,7 +71,7 @@ INLINE val rlcp(val to, val from) val rlcp_tree(val to, val from); val regex_parse(val string, val error_stream); val lisp_parse(val source, val error_stream, val error_return_val, val name); -val read_eval_stream(val stream, val error_stream); +val read_eval_stream(val stream, val error_stream, val hash_bang_support); val parser(val stream, val lineno, val primer); val get_parser(val stream); val parser_errors(val parser); diff --git a/txr.c b/txr.c index 9897bc58..ffd8347a 100644 --- a/txr.c +++ b/txr.c @@ -689,5 +689,5 @@ int txr_main(int argc, char **argv) } } - return read_eval_stream(parse_stream, std_error) ? 0 : EXIT_FAILURE; + return read_eval_stream(parse_stream, std_error, t) ? 0 : EXIT_FAILURE; } -- cgit v1.2.3