in reply to My issues with Parse::RecDescent

Your parser has no way of knowing how to handle non-numbers, so it stops after the first number because there's nothing more it can parse. You could try something like
START: ( number | word )(s)
and add the rule
word: /\w+/,
if that's what you want.

UPDATE: Oops, I forgot that the 'one-or-more' quantifier in Parse::RecDescent is (s), not +. Fixed.

Replies are listed 'Best First'.
Re^2: My issues with Parse::RecDescent
by Alien (Monk) on Aug 26, 2008 at 20:05 UTC
    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 .
      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 !