in reply to P6: Beginning grammar
The input string will be small; should I walk the string or walk the match object? As an exercise, treating the problem like a larger language appeals?
The idiomatic approach is not to iterate at all, but to define an action class with methods that generate the desired datastructures, and storing them in the ast attribute of the current match object.
The grammar chapter of our work-in-progress-book talks about this technique a bit (it's also slightly outdated, and I plan to update it within the next few days). (Update: I've updated it both to match the current spec, and to work with current Rakudo. You can find the examples in the simplified_parsing branch on github.)
$match is supposed to work just like $/, yes?
Yes. And recent development versions of Rakudo also set $/ in Grammar.parse.
Since a few days Rakudo also supports the $/.perl method (Perl 6's built-in version of Data::Dumper), which shows you the structure of the match object.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: P6: Beginning grammar
by rir (Vicar) on Jun 07, 2010 at 21:00 UTC | |
by moritz (Cardinal) on Jun 08, 2010 at 06:47 UTC |