Subject: | with_actions class not called for match not at beginning of string |
Date: | Sat, 9 Jan 2016 17:05:53 -0500 |
To: | bug-Regexp-Grammars [...] rt.cpan.org |
From: | Keith Westgate <westgate [...] gmail.com> |
version : Regexp-Grammars-1.044
perl: This is perl 5, version 12, subversion 2 (v5.12.2) built for
x86_64-linux-thread-multi
os: Linux vlsj-westgate 2.6.18-371.el5 #1 SMP Thu Sep 5 21:21:44 EDT 2013
x86_64 GNU/Linux
I've taken the calc example and was playing with it. I've noticed that when
the match doesn't start at the beginning of the line the with_action in not
called.
You'll notice below then when the data is 4, you see the message "ANSWERED
called" as well as the results being "processed".
however, when i feed it ".4", while it says it matched, I don't see
"ANSWERED called" and the results come back as 4.
output follows:
vlsj-westgate@westgate_ml2@13:56:28> PERL5LIB=/vobs/uth/perl ./x.pl
Show quoted text
data>>> 4
=====> Trying <grammar> from position 0
4\n |...Trying <Answer>
| |...Trying subpattern /\d+/
\n | | \_____subpattern /\d+/ matched '4'
ANSWER called
| \_____<Answer> matched '4'
--> processed
Show quoted textdata>>> .4
=====> Trying <grammar> from position 0
.4\n |...Trying <Answer>
| |...Trying subpattern /\d+/
| | \FAIL subpattern /\d+/
| \FAIL <Answer>
\FAIL <grammar>
=====> Trying <grammar> from position 1
4\n |...Trying <Answer>
| |...Trying subpattern /\d+/
\n | | \_____subpattern /\d+/ matched '4'
| \_____<Answer> matched '4'
--> 4
Show quoted textdata>>>
here's the code:
#!/grid/common/bin/perl -w
use strict;
use v5.10;
use warnings;
my $calculator = do{
use Regexp::Grammars;
qr{
<debug: run>
<Answer>
<rule: Answer>
\d+
}xms
};
print("data>>> ");
while (my $input = <>) {
if ($input =~ $calculator->with_actions('Calculator_Actions') ) {
say '--> ', $/{Answer};
}
print("data>>> ");
}
package Calculator_Actions;
use List::Util qw< reduce >;
sub Answer {
my ($self, $MATCH) = @_;
say "ANSWER called";
my $value = "processed";
return $value;
}
Message body is not shown because sender requested not to inline it.
Message body not shown because it is not plain text.