If I understand the question correctly (and I am not sure I do), you can create a generic peep_seq() using a context variable to get the rule ID, and the rule ID with rule_expand() to get the LHS ID, and the LHS ID to get the symbol name.
On Fri, Mar 13, 2015 at 9:35 PM, <[email protected]> wrote: > Hi! > > To understand better data structure after parsing I created peep action: > > #!/usr/bin/perl > use strict; > use warnings; > use Marpa::R2; > use Data::Dumper; > > my $dsl = <<'END_OF_DSL'; > :default ::= action => [name,values] > lexeme default = latm => 1 > > seq ::= digit seq > action => peep > | digit > > digit ~ [01] > END_OF_DSL > > sub MyActions::peep { > print "peep:\n"; > print Dumper(\@_); > return \@_; > } > > my $grammar = Marpa::R2::Scanless::G->new({ source => \$dsl }); > my $input = '11'; > my $value_ref = $grammar->parse(\$input, 'MyActions'); > print Dumper($value_ref); > > > Output is > > peep: > $VAR1 = [ > {}, > '1', > [ > 'seq', > '1' > ] > ]; > $VAR1 = \[ > {}, > '1', > [ > 'seq', > '1' > ] > ]; > > If comment "action => peep", then output will be: > > $VAR1 = \[ > *'seq',* > '1', > [ > 'seq', > '1' > ] > ]; > > There is one difference: first element 'seq' (no peep) and '{}' (peep). I > can write something like this: > sub MyActions::peep_seq { > print "peep:\n"; > print Dumper(\@_); > shift; > return \('seq', @_); > } > But I must implement such rule for all G1 rules where I use peep action! > Can I implement only one suboutine? > > In contrast I found such solution for OOP-case: > > #!/usr/bin/perl > use strict; > use warnings; > use Marpa::R2; > use Data::Dumper; > > my $dsl = <<'END_OF_DSL'; > :default ::= action => [values] bless => ::lhs > lexeme default = latm => 1 > > seq ::= digit seq > action => peep > | digit > > digit ~ [01] > END_OF_DSL > > sub MyActions::peep { > print "peep:\n"; > print Dumper(\@_); > return $_[1]; > } > > my $grammar = Marpa::R2::Scanless::G->new({ bless_package => 'MyClasses', > source => \$dsl }); > my $input = '11'; > my $value_ref = $grammar->parse(\$input, 'MyActions'); > print Dumper($value_ref); > > Is it ok? > > -- > You received this message because you are subscribed to the Google Groups > "marpa parser" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "marpa parser" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
