Help or Advice appreciated for parsing

Hi,

I am working on some pseudo-www language.

The idea is simple - every HTML tag becomes a method call.

Would become:

h4

And

Test

Would become:

h4 ‘Test’

This works ok-ish, but I am feeling that it is reaching an end here
slowly.

For instance, I actually no longer want to use pure Ruby to interpret
all that.

I would like to be able to do something like:

h4 Test

Optionally, Without any “” or ‘’ Quotes at all.

In other words, I think in the long run I wish to create a real little
“language” and interpret this language instead (and map calls to
functions on my own).

Ok, this hopefully sets a little context of what I am trying to do.

Now I was looking at old code of mine and I noticed something like this:

e ’

This is just a ruby string basically, nothing fancy at all. (7 years old
code or something, I was not even using method calls here).

Now I was thinking “Hmm, I could turn this into a method call, like”:

area :rect, ‘1,1,100,50’,‘www.foobar.com

And this reads a little bit better. It is a bit shorter. Problem is …
it required a fixed argument listing. And it requires one to use ‘,’
too, which I don’t really like either.

Then I was thinking “Hmm, why wouldn’t I not treat those method calls as
real objects instead?” And the params would become messages.

So I then thought “Let’s try this:”

area.shape ‘rect’ .coords ‘1,1,100,50’ .href ‘http://www.foobar.com

Ok, this does not work in Ruby. Even adding () won’t work, the method
chaining happens on String object eventually (and I would have cheated,
area would be def area, so area() instead, returning a specific class
that would respond to methods like shape, coords, href.

I am not really sure if I am able to express what I am trying to
achieve. :slight_smile:

I would like to create a language for the WWW, that is terse, elegant
and avoids repetition. HTML is way too verbose and I would never go back
to write it on my own again anyway.

I am also not sure how this language should look like, either.

area shape: rec coords: 1,1,100,50 href: http://www.foobar.com

I think I am favouring this right now. But this would not be valid Ruby,
so my question would be, basically … how would I turn this into valid
ruby? (It will always be on the same line. New line means something else
happens, some other tag.)

Confused right now…

On Jan 14, 9:09pm, Marc H. [email protected] wrote:

So I then thought “Let’s try this:”

area.shape ‘rext’ .coords ‘1,1,100,50’ .href ‘http://www.foobar.com

Ok, this does not work in Ruby. Even adding () won’t work, the method
chaining happens on String object eventually (and I would have cheated,
area would be def area, so area() instead, returning a specific class
that would respond to methods like shape, coords, href.

There’s no reason that with appropriate parens wouldn’t work. By
appropriate parens I mean

area.shape(‘rect’).coords(‘1,1,100,50’).href(‘http://
www.foobar.com’)

Look into Fluent Interfaces for more info on that sort of thing.

This easily gets into contentious areas like metaprogramming, blank
objects, DSLs, and creating new languages (or dialects). Consider how
much you really want this. Look into already existing projects that
are already in this arena, like, say, HAML.

I am not really sure if I am able to express what I am trying to
achieve. :slight_smile:

Well, that’s something to work on. Good luck.

Have you heard about Markaby and Haml? One of these might be what you
need (unless you just want to write something new for fun).

2012/1/15, Yossef M. [email protected]:

This easily gets into contentious areas like metaprogramming, blank
objects, DSLs, and creating new languages (or dialects). Consider how
much you really want this. Look into already existing projects that
are already in this arena, like, say, HAML.

Well, I would want it if it:

  • simplifies my life
  • reduces the amount of code I have to write

I’ll look into Markaby and Haml, but right now I think none of them
allow to call ruby methods or objects? Which I think I will need to be
able to do …

Anyway, thanks, even if it did not quite help me very much right now.

Markaby is exactly what you describe:

h4 ‘Test’
div do
p ‘Para 1’
p ‘Para 2’
end

http://markaby.rubyforge.org/

On Tue, Jan 17, 2012 at 05:49:08PM +0900, Brian C. wrote:

Markaby is exactly what you describe:

h4 ‘Test’
div do
p ‘Para 1’
p ‘Para 2’
end

Exactly . . . ?

I believe the request also involved wanting to be able to leave out the
quotation marks.

Oh, I see now. Markaby is pure ruby so one could connect it to other
ruby methods and objects just as well.

So that may be a nice way after all.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs