summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-22 01:56:34 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-22 01:56:34 -0800
commit3dc63192610416b6f5765171bceff5bb1f36e701 (patch)
treeb707f4f3ff5969a2b8333a2a1381ea2c8a798ebb /parser.y
parentdebcf6f76029eec890192e8ee5b040b47120f91b (diff)
downloadtxr-3dc63192610416b6f5765171bceff5bb1f36e701.tar.gz
txr-3dc63192610416b6f5765171bceff5bb1f36e701.tar.bz2
txr-3dc63192610416b6f5765171bceff5bb1f36e701.zip
Preparation for lexical macros: we need to pass a macro
environment down through the expander call hierarchy. * eval.c (expand_opt_params, expand_params, expand_tree_cases, expand_tree_case, expand_forms, val expand_cond_pairs, val expand_place, expand_qquote, expand_vars, expand_quasi, expand_op, expand_catch_clause, expand_catch, expand): All expanders get new parameter, menv. expand_forms and expand handle a nil value of menv. (eval_intrinsic): Pass nil macro environment to expand. (eval_init): Update intrinsic registration for expand. * eval.h (expand, expand_forms): Declarations updated. * parser.y (expand_meta): Gets macro env parameter. (elem, o_elem, exprs, expr): Pass nil to expand_forms and expand_meta.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y21
1 files changed, 12 insertions, 9 deletions
diff --git a/parser.y b/parser.y
index 1aec65d5..a2553f88 100644
--- a/parser.y
+++ b/parser.y
@@ -56,7 +56,7 @@ static val lit_char_helper(val litchars);
static val optimize_text(val text_form);
static val unquotes_occur(val quoted_form);
static val choose_quote(val quoted_form);
-static val expand_meta(val form);
+static val expand_meta(val form, val menv);
static wchar_t char_from_name(const wchar_t *name);
static val parsed_spec;
@@ -345,11 +345,11 @@ elem : texts { $$ = rlcp(cons(text_s, $1), $1);
| list { val sym = first($1);
if (sym == do_s || sym == require_s)
$$ = rlcp(cons(sym,
- expand_forms(rest($1))),
+ expand_forms(rest($1), nil)),
$1);
else
$$ = rlcp(cons(sym,
- expand_meta(rest($1))),
+ expand_meta(rest($1), nil)),
$1); }
| COLL exprs_opt ')' elems END { $$ = list(coll_s, $4, nil, $2, nao);
rl($$, num($1)); }
@@ -582,7 +582,8 @@ o_elem : TEXT { $$ = string_own($1);
| SPACE { $$ = string_own($1);
rl($$, num(lineno)); }
| o_var { $$ = $1; }
- | list { $$ = rlcp(cons(expr_s, expand($1)), $1); }
+ | list { $$ = rlcp(cons(expr_s,
+ expand($1, nil)), $1); }
| rep_elem { $$ = $1; }
;
@@ -715,10 +716,10 @@ list : '(' n_exprs ')' { $$ = rl($2, num($1)); }
yybadtoken(yychar, lit("meta expression")); }
;
-exprs : n_exprs { $$ = rlcp(expand_meta($1), $1); }
+exprs : n_exprs { $$ = rlcp(expand_meta($1, nil), $1); }
;
-expr : n_expr { $$ = rlcp(expand_meta($1), $1); }
+expr : n_expr { $$ = rlcp(expand_meta($1, nil), $1); }
;
exprs_opt : exprs { $$ = $1; }
@@ -1115,19 +1116,21 @@ static val choose_quote(val quoted_form)
return unquotes_occur(quoted_form) ? qquote_s : quote_s;
}
-static val expand_meta(val form)
+static val expand_meta(val form, val menv)
{
if (atom(form))
return form;
+ menv = default_arg(menv, make_env(nil, nil, nil));
+
if (car(form) == expr_s)
- return cons(expr_s, expand(rest(form)));
+ return cons(expr_s, expand(rest(form), menv));
{
list_collect_decl (out, ptail);
for (; consp(form); form = cdr(form))
- ptail = list_collect(ptail, expand_meta(car(form)));
+ ptail = list_collect(ptail, expand_meta(car(form), menv));
list_collect_nconc(ptail, form);