summaryrefslogtreecommitdiffstats
path: root/share/txr/stdlib/match.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-02 22:47:07 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-02 22:47:07 -0700
commit0f66ac2b5412eb432f165b680fb495f972f33917 (patch)
tree8b8a7d0fe8be6e167e6f17b1c03ed71e32b0aed7 /share/txr/stdlib/match.tl
parentf386692dede859e99745dae25a8f61cb1d39d940 (diff)
downloadtxr-0f66ac2b5412eb432f165b680fb495f972f33917.tar.gz
txr-0f66ac2b5412eb432f165b680fb495f972f33917.tar.bz2
txr-0f66ac2b5412eb432f165b680fb495f972f33917.zip
matcher: better error handling for backquotes.
* share/txr/stdlib/match.tl (transform-qquote): Handle hash error case with separate pattern. Use compile-error and *match form instead of error. Diagnose splicing unquote and nested quasiquote.
Diffstat (limited to 'share/txr/stdlib/match.tl')
-rw-r--r--share/txr/stdlib/match.tl17
1 files changed, 12 insertions, 5 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl
index df143dac..dca0ebf9 100644
--- a/share/txr/stdlib/match.tl
+++ b/share/txr/stdlib/match.tl
@@ -989,11 +989,9 @@
(defun transform-qquote (syn)
(match-case syn
- ((sys:hash-lit @props . @(coll (@key @val)))
- (if props
- (error "~s: only equal hash tables supported" syn)
- ^@(hash ,*(zip [mapcar transform-qquote key]
- [mapcar transform-qquote val]))))
+ ((sys:hash-lit nil . @(coll (@key @val)))
+ ^@(hash ,*(zip [mapcar transform-qquote key]
+ [mapcar transform-qquote val])))
((sys:struct-lit @type . @args)
^@(struct ,(transform-qquote type)
,*[mapcar transform-qquote args]))
@@ -1003,6 +1001,15 @@
((sys:unquote @pat) (if (symbolp pat)
^(sys:var ,pat)
^(sys:expr ,pat)))
+ ((sys:hash-lit @(have) . @nil)
+ (compile-error *match-form*
+ "only equal hash tables supported"))
+ ((@(or sys:qquote) . @nil)
+ (compile-error *match-form*
+ "pattern-matching quasiquote doesn't support nesting"))
+ ((sys:splice . @nil)
+ (compile-error *match-form*
+ "pattern-matching quasiquote doesn't support splicing"))
((@ca . @cd) (cons (transform-qquote ca)
(transform-qquote cd)))
(@else else)))