Re:Perl 6 Grammars – not only for parsing
by scott_s on Tuesday November 23, 2010 @02:54PM
(#1935085)
It would be wonderful if someone more familiar with Perl 6 could give a code break-down of what is going on.
[ Parent
| on HN ]
I only know Perl 5, but I can figure out enough of it to give an educated guess. It seems like he's using the token returned by the grammar to select a method of the same name. So when he gets the token e404, he'll call the method e404 which does a make "404: Not found"
The grammar is something new in Perl 6, but it looks like there are a bunch of regexes that match different tokens. That makes me wonder how well it handles a buggy, ambiguous grammar, where the regexes overlap and something could be parsed as a token of two or more types. First rule wins?
Guess I should read some of chromatic's book over Thanksgiving so I'd understand more of this...
Re:Perl 6 Grammars – not only for parsing
by colomon on Tuesday November 23, 2010 @04:15PM
(#1935397)
Yes, using
Mysite.parse($req, :actions(Mysite::Actions.new))
says "Parse $req using grammar Mysite and actions Mysite::Actions.new." When a token is found, the action method with the same name is called. As I understand it, the idea with separating token and action like that is one grammar can be associated with more than one set of actions.