develooper Front page | perl.recdescent | Postings from March 2013

Global <skip> directive is quite literal

Thread Next
March 31, 2013 15:26
Global <skip> directive is quite literal
Message ID:
I've been trying to get a global <skip> directive- before all rule
definitions- to work, and it seems it must not be quoted or have any
spaces. It seems to run counter to the Parse::RecDescent
documantation. Following is code, I would expect each variant to
parse, but only the first 2 are OK, and the last crashes with
"Internal error in generated parser code!". Is that intended, or
should I file a bug report?


#!/usr/bin/env perl
use warnings;
use strict;
use Parse::RecDescent;


my $plain_grammar='words : (/\w+/)(s) /\Z/';

sub try_grammar {
  my ($name, $trace, $definition)=@_;
  print $name,": $definition = ";
  print $::RD_HINT=$::RD_TRACE=$trace if defined $trace;
  my $grammar = Parse::RecDescent->new("$definition\n$plain_grammar");
  print defined $grammar->words("Please work") ? "OK" : "Didn't parse";
  print "\n";
  undef $::RD_HINT,$::RD_TRACE;

try_grammar('no skip directive',undef,'');
try_grammar('bare skip',undef,"<skip:\\s*>");
try_grammar('bare skip, with a preceeding space',undef,"<skip: \\s*>");
try_grammar('bare skip, plus sign',undef,"<skip:\\s+>");
try_grammar('qr skip',undef,"<skip: qr/\\s*/>");
try_grammar('apostrophe skip',1,"<skip: '\\s*'>");

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About