From: Erik Veenstra Date: 2006-07-22T06:00:47+09:00 Subject: XML2RB - Executing XML ---------------------------------------------------------------- ENGLISH VERSION http://www.erikveen.dds.nl/xml2rb/index.html ---------------------------------------------------------------- XML VERSION
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. 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...
---------------------------------------------------------------- RUBY 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 { text! "This week, I had to track down a bug in a set of..... } example { snip(:comment=> "XML version") snip(:comment=> "Ruby version 1") snip(:comment=> "Ruby version 2") } snip(:comment=> "DSL") text { text! "Instead of writing an interpreter and coding..... } } section(:title=> "Day One") { snip(:comment=> "Please it on the site") } section(:title=> "Day Two") } } ---------------------------------------------------------------- ENGLISH VERSION (REPEATED) http://www.erikveen.dds.nl/xml2rb/index.html ---------------------------------------------------------------- gegroet, Erik V. - http://www.erikveen.dds.nl/