lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jul 3, 2012, at 2:25 PM, Dirk Laurie wrote:

> I found LuaXML on the lua-users wiki.  It goes from XML to Lua.
> 
> The other way would be nice too.  XML is so verbose …
> I could not find anything either on the wiki or by googling.
> 
> So I wrote the attached.  Here's a sample: the expression
> 
>   macro {name="author-short",
>     names{variable="author",'name form="short"'} }

> Comments welcome.
> <xml.lua>

I know it's not the point of this exercise (which is fun globals abuse) and for clarity it intentionally doesn't handle escaping, but a misfeature in the current design keeps it from being fixable.

>     name{param=val,param=val...,body}
>   where `body` evaluates to a string.  If `body` does not match
>   the pattern "<.*>", it will be formatted by "<%s/>".


There's no way of distinguishing between <a/> as markup and <a/> as a four character sequence, and if bad input causes 'body' to evaluate to those four characters, the result is probably not what the programmer intended.

As an aside, anybody producing XML should probably read http://hsivonen.iki.fi/producing-xml/ .

Jay