diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-04-25 11:04:11 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-04-25 11:04:11 -0700 |
commit | a96d1e927faba7300a3bc4108ff93af97707c947 (patch) | |
tree | ef2176ed392334d523d299588bae2855231e9a06 | |
parent | 8280c77142467d28cafcf2f79dfdb64861f01632 (diff) | |
download | txr-a96d1e927faba7300a3bc4108ff93af97707c947.tar.gz txr-a96d1e927faba7300a3bc4108ff93af97707c947.tar.bz2 txr-a96d1e927faba7300a3bc4108ff93af97707c947.zip |
match: third round of quasi tests and fixes.
* share/txr/stdlib/match.tl (expand-quasi-match): Add case fo
r unbound var followed by var, followed by nothing.
* tests/011/patmatch.tl: New tests.
-rw-r--r-- | share/txr/stdlib/match.tl | 8 | ||||
-rw-r--r-- | tests/011/patmatch.tl | 14 |
2 files changed, 22 insertions, 0 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl index 2cca5322..514b06c6 100644 --- a/share/txr/stdlib/match.tl +++ b/share/txr/stdlib/match.tl @@ -921,6 +921,14 @@ (quasi-match vlist rest (cons sym vars) str npos)))) ;; `@var0@var1` (unbound followed by bound) (((@(eq 'sys:var) @sym) + @(as bvar (@(eq 'sys:var) @(bound-p vlist vars @bsym) . @mods))) + (with-gensyms (txt end) + (list ^@(with ,txt (sys:quasi ,bvar)) + ^@(require @(with ,end (search-str ,str ,txt ,pos)) + ,end (eql (+ , end (len ,txt)) (len ,str))) + ^@(with ,sym (sub-str ,str ,pos ,end))))) + ;; `@var0@var1...` (unbound followed by bound) + (((@(eq 'sys:var) @sym) @(as bvar (@(eq 'sys:var) @(bound-p vlist vars @bsym) . @mods)) . @rest) (with-gensyms (txt end npos) diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl index c40d5ea5..e9685b87 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -350,10 +350,24 @@ (test (when-match `#@a-$` "#a-$" a) "a") (test (when-match `#@a-$` "#a-$$" a) nil) (test (when-match `#@a-$` "#a-" a) nil) +(test (when-match `#@a-@b` "#a-$" (list a b)) ("a" "$")) (test (when-match `#@{a #/ab*c/}` "#abbbc" a) "abbbc") (test (when-match `#@{a #/ab*c/}d` "#abbbcd" a) "abbbc") (test (when-match `#@{a 3}@b` "#abb" a) "abb") (test (when-match `#@{a 3}@b` "#abbbc" (list a b)) ("abb" "bc")) +(test (when-match `#@{a 4}@b` "#abb" a) nil) +(test (when-match `#@{a 3}` "#abb" a) "abb") +(test (when-match `#@{a 2}` "#abb" a) nil) +(test (when-match `#@{a 4}` "#abb" a) nil) + +(macro-time-let ((*stderr* *stdnull*)) + (test (when-match `#@{a 4 5}` "#abb" a) :error)) + +(let ((b "bcd")) + (test (when-match `@a@b` "abcd" a) "a") + (test (when-match `@a@{b [1..:]}` "acd" a) "a") + (test (when-match `@a@{b [1..:]}` "abcd" a) "ab") + (test (when-match `@a@{b [0..1]}` "abcd" a) nil)) (compile-only (eval-only |