summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-01-19 04:34:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-01-19 04:34:18 -0800
commitc5a77bdebfe7daa83eacd6b4e3e208473b5f9ad2 (patch)
tree08f6771c4c04dc563148e33b915bdcd618c866bb /parser.y
parentca741785bfccf52448c5e9a9bdd82778fc976f51 (diff)
downloadtxr-c5a77bdebfe7daa83eacd6b4e3e208473b5f9ad2.tar.gz
txr-c5a77bdebfe7daa83eacd6b4e3e208473b5f9ad2.tar.bz2
txr-c5a77bdebfe7daa83eacd6b4e3e208473b5f9ad2.zip
Bugfix: expand macros in collect, coll, gather.
In the argument lists of @(collect)/@(repeat), @(coll)/@(rep) and @(gather), Lisp expressions can appear as arguments to keywords or for supplying default values for variables. These are not being macro-expanded. * match.c (match_expand_vars): New static function. (match_expand_keyword_args): New function. * match.h (match_expand_keyword_args): Declared. * parser.y (gather_clause, collect_clause, elem): Use new function in match.c to expand the argument lists.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y40
1 files changed, 24 insertions, 16 deletions
diff --git a/parser.y b/parser.y
index 25669f9f..747e3ca3 100644
--- a/parser.y
+++ b/parser.y
@@ -282,20 +282,22 @@ choose_clause : CHOOSE exprs_opt ')'
gather_clause : GATHER exprs_opt ')'
newl gather_parts
- END newl { $$ = list(gather_s,
+ END newl { val args = match_expand_keyword_args($2);
+ $$ = list(gather_s,
append2(mapcar(curry_12_1(func_n2(cons), nil),
first($5)), rest($5)),
- $2, nao);
+ args, nao);
rl($$, num($1)); }
| GATHER exprs_opt ')'
newl gather_parts
until_last exprs_opt ')' newl
clauses_opt
- END newl { $$ = list(gather_s,
+ END newl { val args = match_expand_keyword_args($2);
+ $$ = list(gather_s,
append2(mapcar(curry_12_1(func_n2(cons), nil),
first($5)), rest($5)),
- $2, cons(cdr($6),
+ args, cons(cdr($6),
cons($7, $10)), nao);
rl($$, num($1)); }
@@ -314,19 +316,21 @@ additional_gather_parts : AND newl gather_parts { $$ = $3; }
;
collect_clause : collect_repeat exprs_opt ')' newl
- clauses_opt END newl { $$ = list(car($1),
- $5, nil, $2,
- nao);
- rl($$, cdr($1)); }
+ clauses_opt END newl { val args = match_expand_keyword_args($2);
+ $$ = list(car($1),
+ $5, nil, args,
+ nao);
+ rl($$, cdr($1)); }
| collect_repeat exprs_opt ')'
newl clauses_opt until_last exprs_opt ')'
newl clauses_opt END newl
- { if (nilp($10))
+ { val args = match_expand_keyword_args($2);
+ if (nilp($10))
yyerr("empty until/last in collect");
$$ = list(car($1), $5,
cons(cdr($6),
cons($7, $10)),
- $2, nao);
+ args, nao);
rl($$, cdr($1));
rl($10, car($6)); }
| collect_repeat exprs_opt ')'
@@ -445,23 +449,27 @@ elem : texts { $$ = rlcp(cons(text_s, $1), $1);
$$ = rlcp(cons(sym,
expand_meta(rest($1), nil)),
$1); }
- | COLL exprs_opt ')' elems_opt END { $$ = list(coll_s, $4, nil, $2, nao);
+ | COLL exprs_opt ')' elems_opt END { val args = match_expand_keyword_args($2);
+ $$ = list(coll_s, $4, nil, args, nao);
rl($$, num($1)); }
| COLL exprs_opt ')' elems_opt
until_last exprs_opt ')'
- elems_opt END { $$ = list(coll_s, $4, cons(cdr($5),
+ elems_opt END { val args = match_expand_keyword_args($2);
+ $$ = list(coll_s, $4, cons(cdr($5),
cons($6, $8)),
- $2, nao);
+ args, nao);
rl($$, num($1));
rl($6, car($5)); }
- | REP exprs_opt ')' elems END { $$ = list(rep_s, $4, nil, $2, nao);
+ | REP exprs_opt ')' elems END { val args = match_expand_keyword_args($2);
+ $$ = list(rep_s, $4, nil, args, nao);
rl($$, num($1)); }
| REP exprs_opt ')' elems
until_last exprs_opt ')'
elems END
- { $$ = list(rep_s, $4, cons(cdr($5),
+ { val args = match_expand_keyword_args($2);
+ $$ = list(rep_s, $4, cons(cdr($5),
cons($6, $8)),
- $2, nao);
+ args, nao);
rl($$, num($1));
rl($6, car($5)); }
| COLL error { $$ = nil;