diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-02-02 06:39:06 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-02-02 06:39:06 -0800 |
commit | 78b460717e5fda8bb461101775d2298d365a78a6 (patch) | |
tree | 8fb6338400ce3f1799cf0771d73fee34e271a096 | |
parent | f035e79310802af5370d40589ac7db850eff5a14 (diff) | |
download | txr-78b460717e5fda8bb461101775d2298d365a78a6.tar.gz txr-78b460717e5fda8bb461101775d2298d365a78a6.tar.bz2 txr-78b460717e5fda8bb461101775d2298d365a78a6.zip |
matcher: fix @(and/or) backreferencing issue.
* share/txr/stdlib/match.tl (var-list merge): New method.
(compile-or-match, compile-and-match): After compiling the
sub-patterns, merge all of their new variables produced in
their isolated var-list copies back into var-list, so they are
visible to subsequent compilation.
-rw-r--r-- | share/txr/stdlib/match.tl | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl index 06f028c7..d5063c40 100644 --- a/share/txr/stdlib/match.tl +++ b/share/txr/stdlib/match.tl @@ -120,7 +120,8 @@ vars (:method exists (me sym) (member sym me.vars)) - (:method record (me sym) (push sym me.vars))) + (:method record (me sym) (push sym me.vars)) + (:method merge (me copy) (each ((v copy.vars)) (pushnew v me.vars)))) (defun get-vars (guard-chain) (append-each ((g guard-chain)) @@ -414,6 +415,8 @@ (dj-guard (new guard-disjunction guard-chains (mapcar .guard-chain par-matches) sub-patterns par-matches))) + (each ((vl var-lists)) + var-list.(merge vl)) (new compiled-match pattern par-pat obj-var obj-var @@ -424,6 +427,8 @@ (let* ((var-lists (mapcar (ret (copy var-list)) pats)) (par-matches (mapcar (op compile-match @1 obj-var @2) pats var-lists))) + (each ((vl var-lists)) + var-list.(merge vl)) (new compiled-match pattern par-pat obj-var obj-var |