summaryrefslogtreecommitdiffstats
path: root/match.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 /match.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 'match.c')
-rw-r--r--match.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/match.c b/match.c
index ccc1fa37..cfb1ec2a 100644
--- a/match.c
+++ b/match.c
@@ -3720,47 +3720,54 @@ static val v_load(match_files_ctx *c)
cat_str(nappend2(sub_list(split_str(parent, lit("/")),
zero, negone),
cons(target, nil)), lit("/")));
- int gc = gc_state(0);
val stream, name;
- parser_t parser;
val txr_lisp_p = nil;
open_txr_file(path, &txr_lisp_p, &name, &stream);
- parse_once(stream, name, &parser);
- gc_state(gc);
- if (parser.errors)
- sem_error(specline, lit("~s: errors encountered in ~s"), sym, path, nao);
+ if (!txr_lisp_p) {
+ int gc = gc_state(0);
+ parser_t parser;
+ parse_once(stream, name, &parser);
+ gc_state(gc);
- if (sym == include_s) {
- return parser.syntax_tree;
- } else {
- val spec = parser.syntax_tree;
- val result = match_files(mf_spec(*c, spec));
+ if (parser.errors)
+ sem_error(specline, lit("~s: errors encountered in ~s"), sym, path, nao);
- if (!result) {
- debuglf(specline, lit("load: ~s failed"), path, nao);
- return nil;
+ if (sym == include_s) {
+ return parser.syntax_tree;
} else {
- cons_bind (new_bindings, success, result);
+ val spec = parser.syntax_tree;
+ val result = match_files(mf_spec(*c, spec));
- c->bindings = new_bindings;
-
- if (consp(success)) {
- debuglf(specline,
- lit("load: ~s matched; "
- "advancing from line ~a to ~a"),
- path, c->data_lineno, cdr(success), nao);
- c->data = car(success);
- c->data_lineno = cdr(success);
+ if (!result) {
+ debuglf(specline, lit("load: ~s failed"), path, nao);
+ return nil;
} else {
- debuglf(specline, lit("load: ~s consumed entire file"), path,
- nao);
- c->data = nil;
- }
+ cons_bind (new_bindings, success, result);
- return next_spec_k;
+ c->bindings = new_bindings;
+
+ if (consp(success)) {
+ debuglf(specline,
+ lit("load: ~s matched; "
+ "advancing from line ~a to ~a"),
+ path, c->data_lineno, cdr(success), nao);
+ c->data = car(success);
+ c->data_lineno = cdr(success);
+ } else {
+ debuglf(specline, lit("load: ~s consumed entire file"), path,
+ nao);
+ c->data = nil;
+ }
+
+ return next_spec_k;
+ }
}
+ } else {
+ if (!read_eval_stream(stream, std_error))
+ sem_error(specline, lit("load: ~s contains errors"), path, nao);
+ return (sym == include_s) ? nil : next_spec_k;
}
}
}