Issue #10312 has been updated by Robert A. Heiler.


I would also like to point out that there are already some
limited or perhaps indirect ways to "control" the parser,
in at least one regards, which is the

__END__

construct.

"Invalid" arbitrary syntax can be put after that, and it
is even available for ruby scripts through DATA.read,
which is pretty nifty.

The only complaint I would have is that it must happen
as the last part of a script - it would be nice if it
could happen in the middle of a .rb file too, and 
then there would be another toggle switch to allow me
to tell the ruby parser "ok, continue to evaluate the
rest of that .rb file as if it were valid ruby code
again".

I only wanted to point this out, that we already have
a few ways to control the parser - at least by telling
it to ignore anything that comes after __END__. 

----------------------------------------
misc #10312: Give people more control over how the ruby parser sees code and lexical code elements (valid/invalid - toggle options) + macros
https://bugs.ruby-lang.org/issues/10312#change-49168

* Author: Robert A. Heiler
* Status: Open
* Priority: Low
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
Hi,

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

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 http://haxe.org/ 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'
    use_jquery
  }

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:

  use_jquery

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

Of course the net gain between:

  jquery :+

and

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

Regards.



-- 
https://bugs.ruby-lang.org/