in reply to Re: Parse::RecDescent: problem with grammar and error reporting
in thread Parse::RecDescent: problem with grammar and error reporting

The suggestion doesn't work, it fails at "Even more test address@test.com @20". I guess it's because \S is not a zero-width assertion, it actually wants a non-whitespace character, but those were already gobbled up by [^@\n]*.

"foo bar@" should be allowed.

Interestingly, this version does print the error messages, but I don't understand why.

Replies are listed 'Best First'.
Re^3: Parse::RecDescent: problem with grammar and error reporting
by JavaFan (Canon) on Jan 20, 2012 at 12:12 UTC
    Ah, it's because if one has /PAT1*PAT2*/ Perl prefers to match as many PAT1s as possible, even to the extend of matching less in total. Witness the difference:
    $ perl -wE 'q{Even more test address@test.com @20} =~ /[^@\n]*(?:\S@[^ +@\n]*)*/ and say $&' Even more test address $ perl -wE 'q{Even more test address@test.com @20} =~ /[^@\n]*(?:\S@[^ +@\n]*)+/ and say $&' Even more test address@test.com
    Try this:
    /[^\S\n]*(?:[^\s@]+@?[^\S\n]*)*/

      Nice.

      Only problem with it is that it matches the empty line, which it shouldn't do. This way every line ends up on one unterminated slide, so the parsing fails at the end.

        I'm sure you can fix that yourself, don't you think?