Skip to content

The regex API makes it very difficult to catch syntax errors in the regex. #156

Closed
@natefaubion

Description

@natefaubion

The regex API defers maps a syntax error to a call to fail. Unfortunately this means if you use regex with alt, this failure will probably just get swallowed, and the parser will just fallthrough to the next alternative. This makes it very difficult to track down these errors. I experienced this when writing the json parser benchmarks, which uses regex.

Some alternatives may be:

  • Change the signature to yield a Either String (ParserT String m String), and have unsafeRegex functions which use unsafeCrashWith. This will mean that syntax errors will fail with a hard exception at least, and you'll have a stack trace to the regex call.
  • Change the failure implementation to consume $ fail ... which will set the consume bit so it's less likely to fallthrough. Unfortunately this doesn't work if it's wrapped in try, and it gives you no indication where the error comes from.
  • Provide some sort of hard failure mode in the parser implementation so that it's impossible to recover from it. This still doesn't give you a very good indication where it came from though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions