summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-06-04 17:24:10 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-06-04 17:24:10 -0700
commit18f873d961486e46129eecfa17046faceb369939 (patch)
tree851d083f1aa6d5745f3a9f945b64bd836ec9cacb /match.c
parenta7aa8066a82ac9fd7d2dffe83503b5db739ce3ec (diff)
downloadtxr-18f873d961486e46129eecfa17046faceb369939.tar.gz
txr-18f873d961486e46129eecfa17046faceb369939.tar.bz2
txr-18f873d961486e46129eecfa17046faceb369939.zip
Allow @(repeat) to see variables in more places.
* match.c (extract_vars): With these changes, if @{a b [c..d]} appears inside a @(repeat) or @(rep), variables in the b, c and d positions will be recognized for list iteration, not only a.
Diffstat (limited to 'match.c')
-rw-r--r--match.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/match.c b/match.c
index 2e65cd84..b4306d4a 100644
--- a/match.c
+++ b/match.c
@@ -1646,10 +1646,37 @@ static val extract_vars(val output_spec)
if (consp(output_spec)) {
val sym = first(output_spec);
if (sym == var_s) {
- if (bindable(second(output_spec)))
- tai = list_collect(tai, second(output_spec));
+ val name = second(output_spec);
+ val modifiers = third(output_spec);
+
+ if (bindable(name))
+ tai = list_collect(tai, name);
else
- tai = list_collect_nconc(tai, extract_vars(second(output_spec)));
+ tai = list_collect_nconc(tai, extract_vars(name));
+
+ for (; modifiers; modifiers = cdr(modifiers)) {
+ val mod = car(modifiers);
+ if (bindable(mod)) {
+ tai = list_collect(tai, mod);
+ } else if (consp(mod)) {
+ val msym = car(mod);
+
+ if (msym == dwim_s) {
+ val arg = second(mod);
+
+ if (bindable(arg)) {
+ tai = list_collect(tai, arg);
+ } else if (consp(arg) && car(arg) == rcons_s) {
+ val f = second(arg);
+ val t = third(arg);
+ if (bindable(f))
+ tai = list_collect(tai, f);
+ if (bindable(t))
+ tai = list_collect(tai, t);
+ }
+ }
+ }
+ }
} else if (sym != expr_s) {
for (; output_spec; output_spec = cdr(output_spec))
tai = list_collect_nconc(tai, extract_vars(car(output_spec)));