summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-10-20 07:35:05 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-10-20 07:35:05 -0700
commitc8b05c1e80d9b17a4fb002ee2cd8683632e6184d (patch)
treefd5a3b21943c1e635776b2d2681cc57f1d8cb71b /parser.y
parentb50d160363fd8f2c84b23b03a5f5e9d22911693e (diff)
downloadtxr-c8b05c1e80d9b17a4fb002ee2cd8683632e6184d.tar.gz
txr-c8b05c1e80d9b17a4fb002ee2cd8683632e6184d.tar.bz2
txr-c8b05c1e80d9b17a4fb002ee2cd8683632e6184d.zip
Source file inclusion implemented: needed for macros.
* match.c (include_s): New symbol variable. (v_load): Function extended to handle include semantics. (include): External wrapper function for doing inclusion via v_load. (syms_init): include_s initialized. * match.h (include_s): Declared. (include): Declared. * parser.y (check_for_include): New static function. (clauses_rev): Use check_for_include to replace @(include ..) directive. * txr.1: Documented include. * genvim.txr: Added include symbol. * txr.vim: Regenerated.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y19
1 files changed, 17 insertions, 2 deletions
diff --git a/parser.y b/parser.y
index e8e6069e..7f9ee3d4 100644
--- a/parser.y
+++ b/parser.y
@@ -57,6 +57,7 @@ static val expand_meta(val form, val menv);
static val rlrec(parser_t *, val form, val line);
static wchar_t char_from_name(const wchar_t *name);
static val make_expr(parser_t *, val sym, val rest, val lineno);
+static val check_for_include(val spec_rev);
#if YYBISON
union YYSTYPE;
@@ -146,8 +147,8 @@ spec : clauses { parser->syntax_tree = $1; }
clauses : clauses_rev { $$ = nreverse($1); }
-clauses_rev : clause { $$ = cons($1, nil); }
- | clauses_rev clause { $$ = cons($2, $1); }
+clauses_rev : clause { $$ = check_for_include(cons($1, nil)); }
+ | clauses_rev clause { $$ = check_for_include(cons($2, $1)); }
;
clauses_opt : clauses_rev { $$ = nreverse($1); }
@@ -1305,6 +1306,20 @@ static val make_expr(parser_t *parser, val sym, val rest, val lineno)
return ret;
}
+static val check_for_include(val spec_rev)
+{
+ val line = first(spec_rev);
+
+ if (consp(line)) {
+ val elem = first(line);
+ if (consp(elem)) {
+ if (car(elem) == include_s)
+ return nappend2(nreverse(include(line)), rest(spec_rev));
+ }
+ }
+ return spec_rev;
+}
+
#ifndef YYEOF
#define YYEOF 0
#endif