I have a Regexp::Grammars grammar that fails to match, but succeeds when I turn on debug:
#!/usr/bin/env perl
use feature 'say';
my $parser = do {
use Regexp::Grammars;
qr{
# <debug:step>
\A <command> \Z
<token: command>
<.identifier>+ %% [:]{2}
<token: identifier>
[a-zA-Z0-9_]+
};
};
my $input = 'foo::bar';
if ($input =~ $parser) {
use Data::Dumper; say Data::Dumper::Dumper(\%/);
}
else {
say 'Parse failed!';
}
$ ./grammar_problem.pl
Parse failed!
Turning on debug gets me:
#!/usr/bin/env perl
use feature 'say';
my $parser = do {
use Regexp::Grammars;
qr{
<debug:step>
\A <command> \Z
<token: command>
<.identifier>+ %% [:]{2}
<token: identifier>
[a-zA-Z0-9_]+
};
};
my $input = 'foo::bar';
if ($input =~ $parser) {
use Data::Dumper; say Data::Dumper::Dumper(\%/);
}
else {
say 'Parse failed!';
}
$ ./grammar_problem.pl
=======> Trying <grammar> from position 0
foo::bar |...Trying subpattern /\A/
| \_____subpattern /\A/ matched ''
|...Trying <command>
| |...Trying <.identifier>
| | |...Trying subpattern /[a-zA-Z0-9_]+/
::bar | | | \_____subpattern /[a-zA-Z0-9_]+/ matched 'foo'
| | \_____<.identifier> matched 'foo'
| |...Trying subpattern /[:]{2}/
bar | | \_____subpattern /[:]{2}/ matched '::'
| |...Trying <.identifier>
| | |...Trying subpattern /[a-zA-Z0-9_]+/
[eos] | | | \_____subpattern /[a-zA-Z0-9_]+/ matched 'bar'
| | \_____<.identifier> matched 'bar'
| |...Trying subpattern /[:]{2}/
| | \FAIL subpattern /[:]{2}/
| |...Trying subpattern /[:]{2}/
| | \FAIL subpattern /[:]{2}/
| \_____<command> matched 'foo::bar'
|...Trying subpattern /\Z/
| \_____subpattern /\Z/ matched ''
$VAR1 = {
'' => 'foo::bar',
'command' => 'foo::bar'
};
Any idea what's going on here? Thanks! Stack Overflow says I need more details to submit this, but I don't know what else to say. Typing stuff to get past this. My apologies to the reader!