Mailing List Archive


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

Re: [tlug] Alternatives to sed + awk



On 11 March 2011 09:49, Simon Cozens <simon@example.com> wrote:

> When the Ruby folks say "we can write DSLs without a parser", what they mean
> is option (b), "we can write DSLs that display a lot of Ruby syntax without a
> parser", and therefore what they're actually saying is "we can write subroutines."

Yes, but imagine a DSL such as this:

xml(:doctype => 'html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";') do
  html do
    head do
      title { 'Awesome Page' }
    end
    body do
      h1 { 'Hej!' }
      p do
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
      end
    end
  end
end

Sure, it's Ruby syntax, but it is pretty obvious to any web designer
how to use the DSL, wouldn't you say?

Obviously, this is a trivial DSL that has no real advantages to
straight HTML, but hopefully it serves to illustrate why useful DSLs
are fairly easy in Ruby. Method + block = nice DSL builder.

-- 
Cheers,
Josh


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links