43
votes

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

1 Answers

1
votes

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