Eric Mahurin wrote:

> I don't think trying to push full parser capabilities into regex's is
> the right way to go.  Instead, I think we should have a standard OO
> mechanism in ruby to build grammars - and easily put actions in.  So,
> in your example above, I think we should be able to do something like
> this:
> 
> # we previously defined word, ws, and equal
> assign = word + ws + equal + ws + word

That's a valid point.

Still, my original intent was to point out that the regex syntax may
benefit from an overhaul.  Fine, forget about grammars and such, but as
an example for a possible improvement is that it should be just as easy
to embed a literal string as to embed another regex.

> This is exactly how my grammar package works.  It is LL, but this same
> way of defining grammars could be used LR/LALR parsing or
> DFA/NFA/backtracking of regular expressions.  Instead of specifing
> your entire parser in a very complex string (the regular expression),
> you simply create and combine grammars using methods to make your
> parser (the most basic methods would be for creating an element,
> sequencing (+), alternation (|), and recursion).  You could easily
> associate actions (i.e. ruby blocks) with certain elements with what
> you are trying to parse.  And since this is OO (and duck-typed), we
> wouldn't be limited to just parsing characters like regex's - we could
> parse tokens or whatever.

Well, Perl 6 doesn't define the parser as a very complex string.  It's a
set of regexes - a grammar.  But I'm not saying that that's the best way
to do it.  I like your grammar package and once namespaces are
implemented in Ruby I think that it can be made even sweeter (it's a
little too verbose at the moment).

        nikolai

-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}