4 ms·
To simplify things a bit, I would suggest the use of angle brackets instead of parentheses: <tagname <@ attr "value" attr2 "value2"> <tagname2>
by loup-vaillant 17y ago
To simplify things a bit, I would suggest the use of angle brackets instead of parentheses:
<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.
- loup-vaillant 17y ago[meta] Can someone tell me which line did I cross? I thought my comment above was more than noise.
- Robin_Message 17y agoI think you may have been voted down because the form you have made is not close to S-expressions at all. Sexps are a direct way of encoding a tree of symbols, values and other trees - nothing else. 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.
- wingo 17y agoClose is not enough -- part of the attraction of s-expressions is that they are part of the language. 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%2F&charset=%28detect+automatically%29&doctype=Inline&group=0 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/pub/original/rename-to-index.py.txt, http://wingolog.org/software/original/ http://wingolog.org/software/original/