4 ms·
As a tree, XML syntax is largely isomorphic with that of Lisp's exposed AST.
by brudgers 13y ago
As a tree, XML syntax is largely isomorphic with that of Lisp's exposed AST.
- slashnull 13y agoWell, yeah, but XML has attributes. I was writing about how that was a problem and so on, but I came up with this <look attr="at" attr2="up"> this <awkward> problem </awkward></look> (look (|attr at) (|attr2 up) this (awkward problem)) just by saving "|" as a meta to annotate an attribute pair. And the weird problem of lone tags looking like unclosed ones magically flies away (I think) since <script type="text/javascript" src="foo.js" {">", "/>", "></script>"} is just (script (|type text/javascript) (|src foo.js)) ...sometimes I wonder why isn't everything ever made out of S-exprs.
- brudgers 13y agoLisp has keywords: (look #:attr "at" #:attr2 "up" this (awkward problem)) Or to handle XML on the fly, cons cells are another option: (look '(attr . "at") '(attr2 . "up) this (awkward problem)) Going further since it's Lisp and we're just parsing, we could pretty much use whatever syntax we want by adding a macro: (look (attributes attr "at" attr2 "up") this (awkward problem))