Closed dpk closed 4 months ago
A large part of the motivation is SXPATH-style usage - finding nested patterns in SXML - and I actually use it for this. For example, from the test suite:
(test "sxml tree search"
'(((href . "http://synthcode.com/")) ("synthcode"))
(match '(p (ul (li a (b c) (a (@ (href . "http://synthcode.com/"))
"synthcode") d e f)))
(((or 'p 'ul 'li 'b) *** ('a ('@ attrs ...) text ...))
(list attrs text))
(else #f)))
You would often want _
for the left-hand pattern, but in cases like this can use it to restrict to nesting within certain know tags.
It doesn't match the cars with the right-hand pattern because they are matched by the left-hand pattern, and are accumulated in that binding list. But this is documented as experimental. If you have suggestions for improvement we could consider that. For example, the pattern (*** y)
could allow any path and also match y
against the cars.
Thanks!
What’s the idea of
***
tree patterns in(chibi match)
? (Apologies for this slight abuse of the Chibi issue tracker to ask this question.)As far as I can tell, the left-hand side of the
***
operator is of limited usefulness because it can’t disambiguate between what one might call alternative paths to a matching value: matching both(x *** 'c)
and(x *** 'd)
against(a (b c) (b d))
will bindx
to(a b)
. Also, it never matches the cars of any lists: asked to findd
in(a (b c) (d c))
it will fail.