Misc #10312


Give people more control over how the ruby parser sees code and lexical code elements (valid/invalid - toggle options) + macros

Added by shevegen (Robert A. Heiler) over 8 years ago. Updated about 7 years ago.




I am aware that this proposal has most likely not a chance for
implementation, but I'd still like to make it - this is why I
put it here into misc rather than bugs or features. It's misc -
like ideas!

So first allow me to introduce how I came up with this idea at

I have built a "web framework", which is pretty ugly, but
useful to me. It is actually less of a web framework and
more of a way to describe a "web app" - right now using
valid ruby syntax, but hopefully one day I can transition
into something that is even terser than what it is right
now, and eventually becomes valid ruby (or css or javascript
etc... a bit like HaXe but with a more
elegant syntax resembling ruby rather than java)

I describe a web-page currently such as that way:

w {
title 'My little page'
css_style '
body {
padding: 0.20em;
favicon 'foo/bar.png'
font_size '20px'

Ok, w is simply a method call w() returning an instance of class
WebObject, and we pass it a block. The block I use for a DSL-like
approach to describe the page in question. For instance, use_jquery
simply is in fact w.use_jquery - so it is a method call on that
web object.

Before that, I was using this line here:

jquery :+

The + reminds me of "yes, enable jquery".

Obviously, to disable jquery, I would do:

jquery :-

Then I thought - "Hey, it would be cool if I could do this:

jquery +

instead. In other words, get rid of the : symbol identifier.

But here the ruby parser rightfully chokes because it does not
understand what is meant with jquery +. Fair enough, this is
not valid ruby.

But to my human eyes, jquery + reads nicer than jquery :+

I could get away doing this instead and treat it as a String:

'jquery +'

And simply parse that with ruby. But I already use:


above, so that is nicer IMO than using the two ' characters.

So now, sorry for that long introduction but perhaps you can
understand my line of thought here.

So I was thinking it would be nice if people could get more
control over the Ruby Parser itself.

For instance, in the above example and only for that file/class,
I would like to tell the ruby parser "hey dude, don't mind if
that specific block has invalid syntax, I'd parse on my own.

Possibly it would be enough if those invalid syntax elements
could become strings - then I can parse those strings on my

Of course the net gain between:

jquery :+


jquery +

is minimal, but I love ruby's terse syntax.

Anyway, I am aware that this has no real chance for the ruby
2.x era but perhaps considering all the ideas in regards to
optional static type information and what-not for 3.x ruby era,
more control over the ruby parser itself would be nice
(lisp-like macros!).



Also available in: Atom PDF