From: Eric Mahurin Date: 2005-11-29T09:18:36+09:00 Subject: Re: String#to_rx ? On 11/28/05, Nikolai Weibull wrote: > Well, Perl 6 doesn't define the parser as a very complex string. It's a > set of regexes - a grammar. Yep, your right. Even in perl5, you do it with a set of regexes - where you can do regex recursion with (??{ $re }). This is one or two more languages you have to learn on top of perl - the grammar/regex language. And then trying to integrate actions into this becomes a mess. I think my approach (no new grammar language - just classes, objects, and methods) is a more flexible. > 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). Thanks. There are a few things I'm doing for my next release that will help the verbosity: - the recommended way to make a parser/lexer will be to sub-class Grammar (you can do this in the current release - examples in the next release will do it): class Expression < Grammar def initialize # we don't have to use the Grammar:: prefix all over the place now super(expr) end end g = Expression.new g.scan(...) - make Grammar subclasses (in the package) effectively callable (calling new). To do this, I just defined class and instance methods with the same name as the classes that called klass.new. Before, you would do something like this Grammar::Code.new {...}, and now (with the above sub-classing Grammar for parsers), you'd say Code {...}. I would have had real callable objects like Python, but this seems like a good enough hack.