Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Regex Parsing Style

by aquarium (Curate)
on Nov 26, 2010 at 03:12 UTC ( #873758=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Regex Parsing Style
in thread Regex Parsing Style

that's a heuristic you need to work out. if the alternatives are not exclusive, then the leftest match will always match first. if it was me, i'd run each regex separately and additively collect flags for any matches. then at the end of this parsing you can decide exactly what you want to happen based on combinations of flags..possibly in a switch construct.

the hardest line to type correctly is: stty erase ^H


Comment on Re^3: Regex Parsing Style
Re^4: Regex Parsing Style
by Jim (Curate) on Nov 26, 2010 at 05:13 UTC
    that's a heuristic you need to work out.

    Actually, there was a bug, which ikegami quickly fixed. In the original version of his lexing code, the first two alternative patterns matched every possible valid, non-empty string, making the remaining two alternative patterns unreachable.

    if the alternatives are not exclusive, then the leftest match will always match first.

    I explained the options are mutually exclusive in my original post. It's important that each alternative pattern matches one and only one class of token.

      i believe you that the options are mutually exclusive, but i never program as such. it's difficult to guarantee non-trivial regexes will indeed match exclusively on all input data. and hence i would either pre-run all regexes or other such programming to eliminate non-exclusivity OR allow all regexes to match against input and make normal logic decisions + sane decisions on possible anomalies. that's the kind of defensive programming i'd do if time allows. it's always a balancing act in handling program input, but i think a little scepticism in programming itself is a good thing. hence my advice...even though it's not inline with the spec. take it or leave it as you please.
      the hardest line to type correctly is: stty erase ^H

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-27 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls