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

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

Replies are listed 'Best First'.
Re^4: My issues with Parse::RecDescent
by Anonymous Monk on Aug 26, 2008 at 20:17 UTC
    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
Re^4: My issues with Parse::RecDescent
by Alien (Monk) on Aug 26, 2008 at 20:19 UTC
    Thank you very much , anonymous monk !