This works fine:
(sxml-match '(div)
((div) #t))
But this fails:
(sxml-match '(div)
((,element) #t))
I am wondering how to match any element?
This is a more concrete example. The following is a snippet from the XCB's "xproto.xml" file:
(define xproto '((struct (@ (name "CHAR2B"))
(field (@ (type "CARD8") (name "byte1")))
(field (@ (type "CARD8") (name "byte2"))))
(xidtype (@ (name "WINDOW")))
(xidtype (@ (name "PIXMAP")))
(xidtype (@ (name "ATOM")))
(xidunion (@ (name "DRAWABLE"))
(type "WINDOW")
(type "PIXMAP"))))
My aim is to extract the names:
(define names '((struct "CHAR2B")
(xidtype "WINDOW")
(xidtype "PIXMAP")
(xidtype "ATOM")
(xidunion "DRAWABLE")))
So I tried this:
(sxml-match xproto ((,kind (@ (name ,name)) . ,body) ...))
But I get the error:
bad pattern syntax (not an element pattern)
I do not understand what else I should do.
Is sxml-match
an insufficient tool for this job?
From the Backus-Naur form it follows, doing
(,div)
is not syntactically correct. This matches only theelement-pattern
left symbol and is waiting for atag-symbol
in thecar
position. But it is correct to do(sxml-match '(div) (,element 10))
, as this matches thepat-var-or-cata
rule for a node. So it is a syntax error to do(,something) then
, because,something
matches onlypat-var-or-cata
rule.These rules look very similar to the prepossessing syntax made via some kind of unification.
UPDATE for your example:
I added a constant
@
respectivelyww
for the first 2 levels of nesting on the CAR position, otherwise I do not know if it works.You can zip the results of these 2 expressions to get it.