Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Parse::RecDescent: problem with grammar and error reporting

by kikuchiyo (Monk)
on Jan 20, 2012 at 11:15 UTC ( #948938=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^2: Parse::RecDescent: problem with grammar and error reporting
Select or Download Code
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?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948938]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-08-30 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls