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.
   </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>

RUBY VERSION

post(:title=> “XML2RB”,
:author=> “Erik V.”) {
quote(:src=> “http://www.erikveen.dds.nl/xml2rb/index.html”,
:author=> “Erik V.”) {
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/

It looks interesting, but I am more interested to what do you want to
achieve?

Because if it only the execution graph, there are already tools
outthere to help you out (even ant -debug target will already give you
very good hints).

./alex

.w( the_mindstorm )p.

It looks interesting, but I am more interested to what do you
want to achieve?

What I want to achieve? Well, uh, nothing… That’s one of the
goals in my life. “Don’t achieve anything. You’ll die anyway.”

Sometimes, you have to do things in an unusual way. That’s how
you discover unusual things. This is an experiment. I don’t
know what to expect. If you stick to “the old thinking”, you
don’t achieve anything… ;]

Because if it only the execution graph, there are already
tools outthere to help you out (even ant -debug target will
already give you very good hints).

You’re talking ANT-specific; I’m talking XML in general. My ANT
story is just an example.

Okay, we’re talking ANT-specific now… In order to make
debugging easier, I want to expand all environment variables
(loaded by ). That’s done by
adding 3 pre_conditions [1]. Not bad. (Mmm, could be a subject
for day 3…)

gegroet,
Erik V. - http://www.erikveen.dds.nl/

[1] Ruby Monitor-Functions - Or Meta-Meta-Programming in Ruby

On 7/22/06, Erik V. [email protected] wrote:

Than sorry for disturbing :-). I agree with you about looking outside
the box, but I was trying
to figure out what was your box, and what was outside it.

Because if it only the execution graph, there are already
tools outthere to help you out (even ant -debug target will
already give you very good hints).

You’re talking ANT-specific; I’m talking XML in general. My ANT
story is just an example.

I see… but the intro of the link wasn’t clear about this. And I’ve
heard so many complaints about Ant, so that I thought I will see yet
another one. Now, I don’t want to start a flame, but for me Ant
follows quite well the principle: “let simple things be simple, and
make complex things possible”. I know that many people will like to
argue on this, but till now I haven’t found any good alternatives.

./alex

.w( the_mindstorm )p.

Now, I don’t want to start a flame, but for me Ant follows
quite well the principle: “let simple things be simple, and
make complex things possible”.

Since I would rather say “Ant makes simple things complex and
complex things impossible.”, I’m looking forward to your
motivation.

(Don’t get me wrong. I don’t want to offend you. I’m just
curious.)

… but till now I haven’t found any good alternatives.

Rake? Ruby? It’s not that hard to reimplement Ants
functionality in Ruby. It’s usually a good idea to build a DSL
on top of a GPL, so all common stuff in a language (conditions
and loops) is readily available.

Don’t start from scratch if you’re about to implement a DSL.
You’ll either have to reinvent a lot of wheels, or you just
forget about the wheels and start driving the car without them.

Ant is built from scratch. They skipped the wheels.

gegroet,
Erik V. - http://www.erikveen.dds.nl/

“Erik V.” [email protected] writes:

Rake? Ruby? It’s not that hard to reimplement Ants
functionality in Ruby. It’s usually a good idea to build a DSL
on top of a GPL, so all common stuff in a language (conditions
and loops) is readily available.

Don’t start from scratch if you’re about to implement a DSL.
You’ll either have to reinvent a lot of wheels, or you just
forget about the wheels and start driving the car without them.

Ant is built from scratch. They skipped the wheels.

…but that’s still better than building it on top of Java. :stuck_out_tongue:

On 7/22/06, Erik V. [email protected] wrote:

I will not. But, I have no means to proove it that I can do almost all
I want in Ant and with quite minimal effort.

Also, don’t take me wrong: I haven’t said I can do everything with
Ant. I was able to do what I needed till now (I can assure you that I
have quite a few projects in my portfolio).

… but till now I haven’t found any good alternatives.

Rake? Ruby?

Why would I do that? My IDE doesn’t support neither Rake, nor Ruby. I
don’t have autocompletion for them and documentation hints. What would
be the real benefit? Removing some of the verbosity of XML. I can
agree with that (but let’s not forget that some PL purist find some
verbosity in Ruby too :wink: ).

It’s not that hard to reimplement Ants
functionality in Ruby. It’s usually a good idea to build a DSL
on top of a GPL, so all common stuff in a language (conditions
and loops) is readily available.

Not sure what you are saying here. Ant may be considered a
weak/generic build system DSL, but other than this I am not sure what
are you refering to.

Don’t start from scratch if you’re about to implement a DSL.

I haven’t needed a DSL till now, or at least I haven’t had the feeling
I needed one.

You’ll either have to reinvent a lot of wheels, or you just
forget about the wheels and start driving the car without them.

That’s what I always try to avoid: reinventing. If I can find
something that I can easily use, than here I am. If it is too
difficult than I will try something else.

Ant is built from scratch. They skipped the wheels.

I am not gonna comment on such afirmations. (no intended offense, but
I cannot see the benefit of it :wink: ).

BR,

./alex

.w( the_mindstorm )p.

I’m not sure what you are trying to achieve. Is there a goal
or are you exploring? The answer will change how I read you.

Same question, same answer (please, read post 2 and 3):

"What I want to achieve? Well, uh, nothing… That’s one of the
goals in my life. “Don’t achieve anything. You’ll die anyway.”

Sometimes, you have to do things in an unusual way. That’s how
you discover unusual things. This is an experiment. I don’t
know what to expect. If you stick to “the old thinking”, you
don’t achieve anything… ;]"

gegroet,
Erik V. - http://www.erikveen.dds.nl/

Hi Erik,

On Jul 21, 2006, at 5:00 PM, Erik V. wrote:


ENGLISH VERSION

XML2RB


I’m not sure what you are trying to achieve. Is there a goal or are
you exploring? The answer will change how I read you.

Cheers,
Bob

gegroet,
Erik V. - http://www.erikveen.dds.nl/


Bob H. – blogs at <http://www.recursive.ca/
hutch/>
Recursive Design Inc. – http://www.recursive.ca/
Raconteur – http://www.raconteur.info/
xampl for Ruby – http://rubyforge.org/projects/xampl/

On Jul 23, 2006, at 12:11 PM, Erik V. wrote:

know what to expect. If you stick to “the old thinking”, you
don’t achieve anything… ;]"

I read those, but they don’t quite answer the question :slight_smile:

If your goal is to achieve ‘nothing’ then…

And that it is an experiment says nothing as to whether you are
attempting to do something like resolve a specific problem or to
explore what’s possible.

No matter, I’ll point you to xampl anyway :slight_smile: Xampl is something I’ve
been working on for a long time and have been using for years:
http://rubyforge.org/projects/xampl/ – might be ‘old thinking’
that you’ve never come across before, could be amusing :slight_smile:

Cheers,
Bob

gegroet,
Erik V. - http://www.erikveen.dds.nl/


Bob H. – blogs at <http://www.recursive.ca/
hutch/>
Recursive Design Inc. – http://www.recursive.ca/
Raconteur – http://www.raconteur.info/
xampl for Ruby – http://rubyforge.org/projects/xampl/

On 7/22/06, Erik V. [email protected] wrote:

It looks interesting, but I am more interested to what do you
want to achieve?

What I want to achieve? Well, uh, nothing… That’s one of the
goals in my life. “Don’t achieve anything. You’ll die anyway.”

I guess you have a proof for such a harsh statement :wink:

No, just wanted to say that this seems a really good idea, no more XML,
thus
no more
XHTML ( it will become RHTML ), all browsers talk ruby( so no more
javascript, U R a genius!!!), Matz will replace the W3C and you say
you do not want to achieve anything! Pitty!

Sometimes, you have to do things in an unusual way.

Especially when it is the better way, errr I mean our way.

That’s how

you discover unusual things. This is an experiment. I don’t
know what to expect. If you stick to “the old thinking”, you
don’t achieve anything… ;]

Seriously this is a nice mapping which , I have a feeling, might be a
good
thing to think
about in some design desicion moments.
Cheers
Robert


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein