by loup-vaillant · 16y ago · 0 comments
<tagname <@ attr "value" attr2 "value2">
<tagname2>
<tagname3 "data">>
Going a bit further, we could require the `@`, and place it after the attributes list. This format has fewer special cases: <tagname attr "value" attr2 "value2" @
<tagname2 @>
<tagname3 @"data">>
Finally, we could remove the quotes around the raw strings ("data"), while inverting the brackets: >tagname attr "value" attr2 "value2" @
>tagname2 @<
>tagname3 @data<<
This may look twisted, but we stay very close to true S-expressions, while using the same escape characters we have in plain XML.Thus you can use the language's escaping mechanisms, or put the escaping in your sxml->xml filter.
Preserving XML escapes is not actually a virtue. If you enter your data using S-expressions and validate on transformation, you will never have malformed XML.
(Not in any way that matters, anyway: http://validator.w3.org/check?uri=http%3A%2F%2Fwingolog.org%...)
edit: note also that in this context, s-expressions are more about language and less about parentheses; one can have them in python too: http://wingolog.org/pub/original/rename-to-index.py.txt, http://wingolog.org/software/original/
To give an example of why this is powerful, suppose I decide I need two different namespace of attributes. In your example, this is hard. I can either do:
>tagname attr "value" @ attr "value2" !<
which special cases the parsing, and is hard to understand, or >tagname ns1:attr "value" ns2:attr "value2" @<
which makes it hard to process attributes (xml is like this)Sexps have an easy, obvious solution
(tagname (@ attr "value") (@other attr "value2"))
which I'd argue is clearer, more backward compatible, and doesn't require changing the parser.Now this is only one example, but the point of sexps is they don't have an special cases, and they move the semantics out of the syntax and into the processing.