From: Siemen Baader Date: 2009-11-17T00:40:45+09:00 Subject: Re: Traversing the contents of a proc (for a DSL) --0015175d09de071a4d04787ed510 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Nov 16, 2009 at 1:51 PM, Brian Candler wrote: > Siemen Baader wrote: > > I'm playing with a small DSL for HTML, which should look like this. > > > > html { > > head { title {"Hello World"} } > > body { > > h1 { "hello"} > > p { > > "text body" > > "more text" > > } > > } > > } > > > > If it is possible to recursively traverse through the statements in > > each block, I could join the lines together with the + operator, and > > the implementation would be fairly easy - just recursive calls that > > return text. But it does not look like this is possible... > > Two string literals on the same line are concatenated - so in the above > example you could get away with a simple pre-processor that joins the > lines together in the right places. > > >> "foo" "bar" > => "foobar" > >> > > However this won't work for > > str1 > str2 > > If this is what you want - i.e. each expression appearing on a line of > its own has its value sent to the output string - then probably native > Ruby is not the right tool. HAML, ERB and Cucumber are examples of DSLs > where a non-Ruby syntax fits better. > Yes. Again, this is more an exercise to see what can be done with an inline DSL, so I'll just stick with what I got. It would have been quite easy with Lisp though, as I would have access to each line and join them .. But apart from that, I'm not fluent with Lisp :) > -- > Posted via http://www.ruby-forum.com/. > > --0015175d09de071a4d04787ed510--