Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala PackratParser ignores failure parser

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?

like image 859
adamretter Avatar asked Mar 27 '15 12:03

adamretter


1 Answers

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

like image 180
Aivean Avatar answered Sep 20 '22 09:09

Aivean