E
Erik Veenstra
----------------------------------------------------------------
ENGLISH VERSION
http://www.erikveen.dds.nl/xml2rb/index.html
----------------------------------------------------------------
XML VERSION
<post title="XML2RB"
author="Erik Veenstra">
<quote src="http://www.erikveen.dds.nl/xml2rb/index.html"
author="Erik Veenstra">
<snip comment="money"/>
<snip comment="XML-bashing"/>
<snip comment="XML is great!"/>
<snip comment="Ruby is even greater!"/>
<snip comment="XML-bashing, again"/>
<snip comment="Data and Code"/>
<snip comment="ANT-bashing"/>
<section comment="introduction">
<text>
This week, I had to track down a bug in a set of ANT scripts.
It took me hours. I simply couldn't build a mental picture of
what was going on. I was angry. "I don't want to read XML!", I
shouted. "XML is for machines! I'm not a machine! I want to
write Ruby!" Java Joe answer: "Go write Ruby, I don't care,
but please shut up!". Just to make him happy, I immediately
started writing Ruby...
I wrote a little script to analyze these ANT scripts. After
all, they're just XML and can be treated as data. The parts
which should be treated as code are fed to a little
interpreter, which walked through the data, step-by-step.
Something started to smell... Although I was writing Ruby,
I was still handling XML and, above all, I was still
thinking XML.
Can't we just translate XML to Ruby code? In theory we could:
assume that we translate every tag in XML to a method call in
Ruby, than the attributes of the tag are the named parameters
of the call and the body of the tag (child tags and/or text)
is handled by the block.
</text>
<example>
<snip comment="XML version"/>
<snip comment="Ruby version 1"/>
<snip comment="Ruby version 2"/>
</example>
<snip comment="DSL"/>
<text>
Instead of writing an interpreter and coding against REXML, we
only have to build the DSL. Or can it be generated?...
Let's turn theory into practice. After all that's the best
proof of a concept. "In theory, there's no difference between
theory and practice; in practice, there is."
This is just an experiment. Maybe, after a couple of days, I
say: "Stupid idea!" Maybe not. Let's find out...
</text>
</section>
<section title="Day One">
<snip comment="Please it on the site"/>
</section>
<section title="Day Two">
<!-- TODO: Not yet implemented -->
</section>
</quote>
</post>
----------------------------------------------------------------
RUBY VERSION
posttitle=> "XML2RB",
:author=> "Erik Veenstra") {
quotesrc=> "http://www.erikveen.dds.nl/xml2rb/index.html",
:author=> "Erik Veenstra") {
snipcomment=> "money")
snipcomment=> "XML-bashing")
snipcomment=> "XML is great!")
snipcomment=> "Ruby is even greater!")
snipcomment=> "XML-bashing, again")
snipcomment=> "Data and Code")
snipcomment=> "ANT-bashing")
sectioncomment=> "introduction") {
text {
text! "This week, I had to track down a bug in a set of.....
}
example {
snipcomment=> "XML version")
snipcomment=> "Ruby version 1")
snipcomment=> "Ruby version 2")
}
snipcomment=> "DSL")
text {
text! "Instead of writing an interpreter and coding.....
}
}
sectiontitle=> "Day One") {
snipcomment=> "Please it on the site")
}
sectiontitle=> "Day Two")
}
}
ENGLISH VERSION
http://www.erikveen.dds.nl/xml2rb/index.html
----------------------------------------------------------------
XML VERSION
<post title="XML2RB"
author="Erik Veenstra">
<quote src="http://www.erikveen.dds.nl/xml2rb/index.html"
author="Erik Veenstra">
<snip comment="money"/>
<snip comment="XML-bashing"/>
<snip comment="XML is great!"/>
<snip comment="Ruby is even greater!"/>
<snip comment="XML-bashing, again"/>
<snip comment="Data and Code"/>
<snip comment="ANT-bashing"/>
<section comment="introduction">
<text>
This week, I had to track down a bug in a set of ANT scripts.
It took me hours. I simply couldn't build a mental picture of
what was going on. I was angry. "I don't want to read XML!", I
shouted. "XML is for machines! I'm not a machine! I want to
write Ruby!" Java Joe answer: "Go write Ruby, I don't care,
but please shut up!". Just to make him happy, I immediately
started writing Ruby...
I wrote a little script to analyze these ANT scripts. After
all, they're just XML and can be treated as data. The parts
which should be treated as code are fed to a little
interpreter, which walked through the data, step-by-step.
Something started to smell... Although I was writing Ruby,
I was still handling XML and, above all, I was still
thinking XML.
Can't we just translate XML to Ruby code? In theory we could:
assume that we translate every tag in XML to a method call in
Ruby, than the attributes of the tag are the named parameters
of the call and the body of the tag (child tags and/or text)
is handled by the block.
</text>
<example>
<snip comment="XML version"/>
<snip comment="Ruby version 1"/>
<snip comment="Ruby version 2"/>
</example>
<snip comment="DSL"/>
<text>
Instead of writing an interpreter and coding against REXML, we
only have to build the DSL. Or can it be generated?...
Let's turn theory into practice. After all that's the best
proof of a concept. "In theory, there's no difference between
theory and practice; in practice, there is."
This is just an experiment. Maybe, after a couple of days, I
say: "Stupid idea!" Maybe not. Let's find out...
</text>
</section>
<section title="Day One">
<snip comment="Please it on the site"/>
</section>
<section title="Day Two">
<!-- TODO: Not yet implemented -->
</section>
</quote>
</post>
----------------------------------------------------------------
RUBY VERSION
posttitle=> "XML2RB",
:author=> "Erik Veenstra") {
quotesrc=> "http://www.erikveen.dds.nl/xml2rb/index.html",
:author=> "Erik Veenstra") {
snipcomment=> "money")
snipcomment=> "XML-bashing")
snipcomment=> "XML is great!")
snipcomment=> "Ruby is even greater!")
snipcomment=> "XML-bashing, again")
snipcomment=> "Data and Code")
snipcomment=> "ANT-bashing")
sectioncomment=> "introduction") {
text {
text! "This week, I had to track down a bug in a set of.....
}
example {
snipcomment=> "XML version")
snipcomment=> "Ruby version 1")
snipcomment=> "Ruby version 2")
}
snipcomment=> "DSL")
text {
text! "Instead of writing an interpreter and coding.....
}
}
sectiontitle=> "Day One") {
snipcomment=> "Please it on the site")
}
sectiontitle=> "Day Two")
}
}