[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

XML2RB - Executing XML

Erik Veenstra

7/21/2006 9:01:00 PM

----------------------------------------------------------------

ENGLISH VERSION

http://www.erikve...xml2rb/...

----------------------------------------------------------------

XML VERSION

<post title="XML2RB"
author="Erik Veenstra">
<quote src="http://www.erikve...xml2rb/..."
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

post(:title=> "XML2RB",
:author=> "Erik Veenstra") {
quote(:src=> "http://www.erikve...xml2rb/...",
: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.erikve...xml2rb/...

----------------------------------------------------------------

gegroet,
Erik V. - http://www.erikve...


9 Answers

Alexandru Popescu

7/21/2006 10:52:00 PM

0

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.


On 7/22/06, Erik Veenstra <erikveen@gmail.com> wrote:
> ----------------------------------------------------------------
>
> ENGLISH VERSION
>
> http://www.erikve...xml2rb/...
>
> ----------------------------------------------------------------
>
> XML VERSION
>
> <post title="XML2RB"
> author="Erik Veenstra">
> <quote src="http://www.erikve...xml2rb/..."
> 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
>
> post(:title=> "XML2RB",
> :author=> "Erik Veenstra") {
> quote(:src=> "http://www.erikve...xml2rb/...",
> :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.erikve...xml2rb/...
>
> ----------------------------------------------------------------
>
> gegroet,
> Erik V. - http://www.erikve...
>
>
>

Erik Veenstra

7/22/2006 10:58:00 AM

0

> 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 <property environment="env"/> ). That's done by
adding 3 pre_conditions [1]. Not bad. (Mmm, could be a subject
for day 3...)

gegroet,
Erik V. - http://www.erikve...

[1] http://www.erikve...monitorfunctions/index.html#4.0.0


Alexandru Popescu

7/22/2006 11:24:00 AM

0

On 7/22/06, Erik Veenstra <erikveen@gmail.com> 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."
>
> 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... ;]
>

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.


> Okay, we're talking ANT-specific now... In order to make
> debugging easier, I want to expand all environment variables
> (loaded by <property environment="env"/> ). That's done by
> adding 3 pre_conditions [1]. Not bad. (Mmm, could be a subject
> for day 3...)
>
> gegroet,
> Erik V. - http://www.erikve...
>
> [1] http://www.erikve...monitorfunctions/index.html#4.0.0
>
>
>

Erik Veenstra

7/22/2006 12:05:00 PM

0

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


Christian Neukirchen

7/22/2006 5:18:00 PM

0

"Erik Veenstra" <erikveen@gmail.com> 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. :-P

> gegroet,
> Erik V. - http://www.erikve...
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Alexandru Popescu

7/22/2006 6:48:00 PM

0

On 7/22/06, Erik Veenstra <erikveen@gmail.com> wrote:
> > 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.)
>

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 ;-) ).


> 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 ;-) ).

BR,

/alex
--
w( the_mindstorm )p.

> gegroet,
> Erik V. - http://www.erikve...
>
>
>

Bob Hutchison

7/23/2006 3:56:00 PM

0

Hi Erik,

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

> ----------------------------------------------------------------
>
> ENGLISH VERSION
>
> http://www.erikve...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.erikve...
>
>

----
Bob Hutchison -- blogs at <http://www.rec...
hutch/>
Recursive Design Inc. -- <http://www.rec...>
Raconteur -- <http://www.raconteur...
xampl for Ruby -- <http://rubyforge.org/projects/...




Erik Veenstra

7/23/2006 4:12:00 PM

0

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


Bob Hutchison

7/23/2006 4:28:00 PM

0


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

>> 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... ;]"

I read those, but they don't *quite* answer the question :-)

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 :-) Xampl is something I've
been working on for a long time and have been using for years:
<http://rubyforge.org/projects/... -- might be 'old thinking'
that you've never come across before, could be amusing :-)

Cheers,
Bob


>
> gegroet,
> Erik V. - http://www.erikve...
>
>

----
Bob Hutchison -- blogs at <http://www.rec...
hutch/>
Recursive Design Inc. -- <http://www.rec...>
Raconteur -- <http://www.raconteur...
xampl for Ruby -- <http://rubyforge.org/projects/...