in reply to Re: My issues with Parse::RecDescent
in thread My issues with Parse::RecDescent

I tried modifying the script , but now I get an error calling the constructor :
use strict; use Parse::RecDescent; my $grammar = q( START: ( number | word )+ word: /\w+/ { print "found a word\n"; } number: /\d+/ { print "found a number\n"; } ); Parse::RecDescent->new($grammar)->START("123 geo 456 bam");

I know I'm a pain in the a** , but please bear with me .

Replies are listed 'Best First'.
Re^3: My issues with Parse::RecDescent
by Anonymous Monk on Aug 26, 2008 at 20:15 UTC
    D:\>perl use strict; use Parse::RecDescent; my $grammar = q( START: ( number | word )+ word: /\w+/ { print "found a word\n"; } number: /\d+/ { print "found a number\n"; } ); Parse::RecDescent->new($grammar)->START("123 geo 456 bam"); __END__ ERROR (line 2): Untranslatable item encountered: "+" (Hint: Set $::RD_HINT (or -RD_HINT if you're using "pe +rl -s") for hints on fixing these problems.) Can't call method "START" on an undefined value at - line 10. D:\>perl $::RD_HINT=1; use strict; use Parse::RecDescent; my $grammar = q( START: ( number | word )+ word: /\w+/ { print "found a word\n"; } number: /\d+/ { print "found a number\n"; } ); Parse::RecDescent->new($grammar)->START("123 geo 456 bam"); __END__ ERROR (line 2): Untranslatable item encountered: "+" (Hint: Did you misspell "+" or forget to comment it ou +t?) Can't call method "START" on an undefined value at - line 11. D:\>perl $::RD_HINT=1; use strict; use Parse::RecDescent; my $grammar = q( START: ( number | word )(s) word: /\w+/ { print "found a word\n"; } number: /\d+/ { print "found a number\n"; } ); Parse::RecDescent->new($grammar)->START("123 geo 456 bam"); __END__ found a number found a word found a number found a word
      Subrules may also be specified with a trailing repetition specifier, indicating that they are to be (greedily) matched the specified number of times. The available specifiers are:
      subrule(?) # Match one-or-zero times subrule(s) # Match one-or-more times subrule(s?) # Match zero-or-more times subrule(N) # Match exactly N times for integer N > 0 subrule(N..M) # Match between N and M times subrule(..M) # Match between 1 and M times subrule(N..) # Match at least N times
      Thank you very much , anonymous monk !