From 3fbb5bf2be99ab52d5c927c3d467b8d1412abdaf Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 26 Oct 2021 19:07:10 -0700 Subject: match: unquoted quasiliteral patterns don't work. * tests/011/patmatch.tl: Add failing test cases. * txr.1: Document desired requirements. --- tests/011/patmatch.tl | 5 +++++ txr.1 | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl index 09d294a8..da2f8de4 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -526,3 +526,8 @@ (eval-only (compile-file (base-name *load-path*) "temp.tlo") (remove-path "temp.tlo"))) + +(mtest + (match @`foo-@a` "foo-abc" a) "abc" + (match ^(,`foo-@a`) '("foo-abc") a) "abc" + (match ^#J[~`foo-@a`] #("foo-abc") a) "abc") diff --git a/txr.1 b/txr.1 index e41b36ff..f51f0740 100644 --- a/txr.1 +++ b/txr.1 @@ -42369,6 +42369,7 @@ that being a syntactic sugar for .NP* Quasiliteral match .synb .mets <> "`...@" var "...`" +.mets <> @"`...@" var "...`" .syne .desc The quasiliteral syntax is supported as a pattern-matching operator. @@ -42380,6 +42381,18 @@ object isn't a string according to then the match fails. The quasiliteral pattern must match the entire input string. +In order that the quasiliteral's syntactic structure is not misinterpreted +as a predicate pattern, and in order to make certain situations work +in quasiquoted pattern matching, a quasiliteral pattern may be specified +as either +.code "`...`" +or +.codn "@`...`" . +The latter form, which is structurally +.code "(sys:expr (sys:quasi ...))" +is specially recognized and treated as equivalent to the unadorned +quasiliteral pattern. + A quasiliteral pattern matches in a linear fashion, from left to right. Variables bound earlier in the pattern can be referenced later in the pattern as bound variables. @@ -42571,10 +42584,23 @@ otherwise it is translated to the .meti (sys:expr << expr ) .onom syntax. +.coIP ",`...quasilit...`" +An unquoted quasiliteral is treated uniformly as +.mono +.meti >> , expr +.onom +and is therefore translated into +.codn "@`...quasilit...`" . +Since that is equivalent to +.codn "`...quasilit...`" , +quasiteral matching is supported within quasiquote notation +in a straightforward way. .meIP >> ~ expr In JSON syntax, unquotes are given the same above treatment as .code , (comma) unquotes in ordinary syntax. +.coIP ~`...quasilit...` +Similarly, quasiliterals are supported in JSON syntax. .meIP #H(() >> ( k0 << v0 ) >> ( k1 << v1 ) ...) Hash quasiliteral syntax is translated according to the .mono -- cgit v1.2.3