http://qs321.pair.com?node_id=842792

rir has asked for the wisdom of the Perl Monks concerning the following question:

#!/home/rir/rakudo/parrot_install/bin/perl6 grammar OP { token TOP { <op>+ } token op { <cop> | <sop> | <bop> } token cop { # constrained <short> <sep> <long> <div> <char>+ } token sop { # string <short> <sep> <long> <div> } token bop { # bool <short> <sep> <long> } token long { \w+ } token short { \w } token char { # XXX Rename flag. Eliminate '_'. \w } rule sep { ':' } rule div { '/' } } my $s = 'a:aaa b:bbb/ c:ccccc/def'; my $match = OP.parse($s); die "failed" unless $match; say '$match<op>: ', $match<op>; say '$match.from: ', $match.from, ' $match.to: ', $match.to; say '$match.chars: ', $match.chars; say '$match.orig: ', $match.orig; say '$match.Str: ', $match.Str; say '$match.ast: ', $match.ast; say '$match.caps: is not found'; say '$match.pos: is not found'; my @array = $match; say '@array = $match; then @array: ['; for @array -> $i { say $i ; } say "]";
I have a match object that doesn't appear to contain what I'd like. The examples, I've found, are not working for me; I find SO5 a bit thick. Attempting this with a grammar is a learning exercise.

In the above, I'd like to grab ops, know their "type" and insert into a hash keyed on the shorts.

Is this arranged correctly to avoid a partial sop matching as a bop?

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?

How do I traverse $match?

$match is supposed to work just like $/, yes?

I don't care to capture seps or divs but I would like to abstract the values. Should this be done in the grammar? --by variables?

Be well,
rir -- swimming a sea of sticky voluminous syntax errors all alike