summaryrefslogtreecommitdiffstats
path: root/stdlib/match.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-12-27 13:26:01 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-12-27 13:26:01 -0800
commit724187e4d22b26cc81e1d7b0d9b95306cbddc9e2 (patch)
treeb13d13aab6176e6a8f004b7fdd1272cbdd3e2d72 /stdlib/match.tl
parent3f6a55831805e755812aef6ddd4197384dbc822d (diff)
downloadtxr-724187e4d22b26cc81e1d7b0d9b95306cbddc9e2.tar.gz
txr-724187e4d22b26cc81e1d7b0d9b95306cbddc9e2.tar.bz2
txr-724187e4d22b26cc81e1d7b0d9b95306cbddc9e2.zip
match: allow bound variables with regex modifier.
* stdlib/match.tl (expand-quasi-match): Add regex cases with bound variable. * tests/011/patmatch.tl: Test cases for this. * txr.1: Documented.
Diffstat (limited to 'stdlib/match.tl')
-rw-r--r--stdlib/match.tl11
1 files changed, 11 insertions, 0 deletions
diff --git a/stdlib/match.tl b/stdlib/match.tl
index 4a326fdb..30bf1cab 100644
--- a/stdlib/match.tl
+++ b/stdlib/match.tl
@@ -926,6 +926,17 @@
(cons ^@(require @(with ,npos (+ ,pos (len ,txt)))
(match-str ,str ,txt ,pos))
(quasi-match vlist rest vars str npos))))
+ ;; `@{var #/rx/}` (existing binding)
+ (((@(eq 'sys:var) @(bound-p vlist vars @sym) (@(regexp @reg))))
+ (list ^@(require @nil (equal ,sym (m^$ ,reg (sub-str ,str ,pos t))))))
+ ;; `@{var #/rx/}@...` (existing binding)
+ (((@(eq 'sys:var) @(bound-p vlist vars @sym) (@(regexp @reg))) . @rest)
+ (with-gensyms (len npos)
+ (list* ^@(require @(with ,len (match-regex ,str ,reg ,pos))
+ ,len)
+ ^@(with ,npos (+ ,pos ,len))
+ ^@(require @nil (equal ,sym (sub-str ,str ,pos ,npos)))
+ (quasi-match vlist rest vars str npos))))
;; `@var` (existing binding)
(((@(eq 'sys:var) @(bound-p vlist vars @sym) . @nil))
(list ^@(require @nil (match-str ,str (sys:quasi ,(car args))