43

I have a parser that was written using Scala's RegexParsers - link

It had some serious performance problems when parsing a grammar which had deeply nested expressions. As such I have created a version where I mix in Scala's PackratParsers - link

The Packrat version does not exhibit the same performance issue and correctly parses the grammar. However, when I provide an invalid grammar for testing, e.g. this

The old (non-packrat) parser used to correctly report the 'Invalid rule' failure, via the failure parser combinator | failure("Invalid rule") here - link

When using the packrat-parser version, if I enable tracing I can see from the trace that the failure is created just as it is in the non-packrat version, however the PackratParser seems to ignore this and always return failure: Base Failure instead.

Is there something different about failure handling when using PackratParsers which I need to understand?

1 Answer 1

1

Seems that you need to use err("Invalid rule") instead of failure, as it guarantees that no backtracking will be performed.

1
  • If I use err("Invalid rule") instead of failure("Invalid rule") then because backtracking has stopped, many of my other rules that were previously valid start returning err("Invalid rule") which is not correct.
    – adamretter
    Oct 27, 2015 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.