New syntax for string mixins
Jacob Carlborg
doob at me.com
Thu Dec 16 14:30:36 PST 2010
On 2010-12-16 21:13, Nick Sabalausky wrote:
> "Jacob Carlborg"<doob at me.com> wrote in message
> news:iednio$2vj5$1 at digitalmars.com...
>>
>> I can't quite visualize how the final code will look like and as you say
>> it's hard without a formal definition of AST macros. But I think somehow
>> it would be possible, I mean instead of combining strings one combine
>> expressions/syntax. But I don't know if it would be possible to combine
>> incomplete expressions.
>>
>
> One parallel that may or may not be applicable, but might be worth
> considering, is dynamically building XHTML: Using a string-template system
> is generally found to work very well, but building it via a DOM (essentially
> an AST) is often considered a bit of a pain. I guess the simplest take-away
> would be that string-based approaches may be easier get working well. FWIW.
I the case of XML I think it can be quite easy if you use the right
libraries/tools. I think the easiest library I've used for building XML
files is the Ruby library Bulilder, a code example using Builder can
look like this:
xml = Builder::XmlMarkup.new
xml.person do
xml.first_name "John"
xml.last_name "Doe"
xml.phone "5484654", :type => "mobile"
end
Which will generate this:
<person>
<first_name>John</first_name>
<last_name>Doe</last_name>
<phone type="mobile">5484654</phone>
</person
Now I don't think that this library is a DOM library, which allows you
to manipulate a DOM tree, it's something simpler that just generates XML.
Link: http://builder.rubyforge.org/
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list