summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-06-12 22:00:38 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-06-12 22:00:38 -0700
commit06e69904744f6349dc4be58f36bd4575497f2106 (patch)
tree452270e12baac8590f716a4ef079b78a8058306a /parser.c
parentfbf525ae910ae48b1e6401fd2307772e214b1baa (diff)
downloadtxr-06e69904744f6349dc4be58f36bd4575497f2106.tar.gz
txr-06e69904744f6349dc4be58f36bd4575497f2106.tar.bz2
txr-06e69904744f6349dc4be58f36bd4575497f2106.zip
@(load) and @(include) now load Lisp code.
* match.c (v_load): Check txr_lisp_p flag coming out of open_txr_file and handle the Lisp case usin read_eval_stream. * parser.c (read_eval_stream, get_parser, parser_errors): New functions. * parser.h (read_eval_stream, get_parser, parser_errors): Declared.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/parser.c b/parser.c
index 2cebed04..86511fdf 100644
--- a/parser.c
+++ b/parser.c
@@ -251,6 +251,36 @@ 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 error_val = gensym(nil);
+
+ for (;;) {
+ val form = lisp_parse(stream, error_stream, error_val, nil);
+
+ if (form == error_val) {
+ if (parser_errors(get_parser(stream)) == zero)
+ break;
+ return nil;
+ }
+
+ (void) eval_intrinsic(form, nil);
+ }
+
+ return t;
+}
+
+val get_parser(val stream)
+{
+ return gethash(stream_parser_hash, stream);
+}
+
+val parser_errors(val parser)
+{
+ parser_t *p = coerce(parser_t *, cobj_handle(parser, parser_s));
+ return num(p->errors);
+}
+
void parse_init(void)
{
parser_s = intern(lit("parser"), user_package);