use strict;
use warnings;
use 5.012;
use Parse::RecDescent;
$::RD_ERRORS = 1; #Parser dies when it encounters an error
$::RD_WARN = 1; #Enable warnings - warn on unused rules &c.
$::RD_HINT = 1; #Give out hints to help fix problems.
#$::RD_TRACE = 1; #Trace parsers' behaviour
my $text = <<'END_OF_TEXT';
{{ hello }}
END_OF_TEXT
my $grammar = <<'END_OF_GRAMMAR';
{
use 5.012;
use Data::Dumper;
}
startrule: lbrace(2)
'hello'
rbrace(2)
lbrace: / [{] /xms
rbrace: / [}] /xms
END_OF_GRAMMAR
my $parser = Parse::RecDescent->new($grammar)
or die "Bad grammar!\n";
defined $parser->startrule($text)
or die "Can't match text";
####
startrule:
####
startrule: lbrace(2) { $lbrace = length $item[1] }
'hello'
rbrace(2)
####
startrule:
startrule: lbrace(2) { $lbrace_count = length $item[1] }
'hello'
lbrace: / [{] /xms
rbrace: / [}] /xms
####
Unknown starting rule (Parse::RecDescent::namespace000001::rbrace(18)) called
at prd1.pl line 39.
####
startrule: lbrace(2)
'hello'
lbrace: / [{] /xms
rbrace: / [}] /xms
--output:--
Unknown starting rule (Parse::RecDescent::namespace000001::rbrace(2)) called
at prd1.pl line 39.
####
use strict;
use warnings;
use 5.012;
use Parse::RecDescent;
$::RD_ERRORS = 1; #Parser dies when it encounters an error
$::RD_WARN = 1; #Enable warnings - warn on unused rules &c.
$::RD_HINT = 1; #Give out hints to help fix problems.
$::RD_TRACE = 1; #Trace parsers' behaviour
my $text = <<'END_OF_TEXT';
{{ hello }}
END_OF_TEXT
my $grammar = <<'END_OF_GRAMMAR';
{
use 5.012;
use Data::Dumper;
}
startrule:
startrule: lbrace(2) { $lbrace_count = length $item[1] }
'hello'
lbrace: / [{] /xms
rbrace: / [}] /xms
END_OF_GRAMMAR
my $parser = Parse::RecDescent->new($grammar)
or die "Bad grammar!\n";
#ERRROR ON NEXT LINE *****************************
defined $parser->startrule($text)
or die "Can't match text";