Inside an action, there's the Marpa::R2::Context::location method, which
returns the start and end G1 locations. G1 locations can be translated
to spans in the input by the g1_location_to_span() method. Getting
location is a two-stage process, because Marpa allows you to jump around
in the input, so the relations of parse (G1) location to input stream
location can, in principle, be extremely complex.
If you are dealing with locations a lot, the AST method may be better.
That is, you use array descriptor actions like "action => [ start,
length, value ]", return the parse value as a tree, then post-process
the tree. The array descriptor action's "start" and "length" are input
stream locations, which is probably what you want.
In case you're worried about the effect of a two-stage process on
efficiency,the array descriptor actions are built in optimized XS code
using a special stack, and the process is blazingly fast. You have to
process the AST in pure Perl, but because doing it in a separate stage
allows you to more easily make your own optimizations.
Sorry I didn't put in some links, but I'm having Internet connection
troubles, so I'm sticking to a raw email.
-- jeffrey
On 06/26/2014 05:50 AM, Ion Toloaca wrote:
One last question and I suppose the problem will be solved.
Can I also access the location where the rule got matched within the
action?
When using events I used something along the lines:
/////////////////////////////////////////////////////////////////////////
my $pos = $recce->read( \"$input", $start, $length - $start );
......................
my ($start_rule, $length_rule) = $recce->last_completed($name);
my $last_expression = $recce->substring($start_rule, $length_rule);
push @$actual_events, [$pos - length($last_expression) +1,$pos+1, $_];
#Marpa counted unicode symbol length incorrectly - so that's a work
around....
.......................
eval {$pos = $recce->resume(); };
/////////////////////////////////////////////////////////////////////////
This way I found the positions where the notations/arguments matched
- can I rewrite this using actions?
--
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]
<mailto:[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.