Problems with abc example
It is quite easy to get parboiled to throw an IllegalStateException with the a^n b^n c^n example, e.g. with input abbbbbcc or aaabbbbbbbbcc:
Enter an a^n b^n c^n expression (single RETURN to exit)!
aaabbbbbbbbcc
Exception in thread "main" java.lang.IllegalStateException
at org.parboiled.common.Preconditions.checkState(Preconditions.java:119)
at org.parboiled.parserunners.RecoveringParseRunner.run(RecoveringParseRunner.java:149)
at org.parboiled.parserunners.AbstractParseRunner.run(AbstractParseRunner.java:81)
at org.parboiled.parserunners.AbstractParseRunner.run(AbstractParseRunner.java:76)
at flow.test.ParserTest.main(ParserTest.java:46)
The exception is thrown here:
public ParsingResult<V> run(InputBuffer inputBuffer) {
// [...]
if (!lastParsingResult.matched) {
// [...]
if (!getRootMatcher().isNodeSuppressed()) {
performFinalRun();
checkState(lastParsingResult.matched); // <-- here
}
}
return lastParsingResult;
}
I have just started using parboiled, but from what I can tell, an internal exception of this kind should not be thrown here. Is this correct?
Furthermore, it is possible to get the parser to seemingly accept invalid input as valid, e.g. aabbbcc gets read as aabbcc:
Enter an a^n b^n c^n expression (single RETURN to exit)!
aabbbcc
aabbbcc = null
[S]E 'aabbcc'
[OneOrMore] 'aa'
['a'] 'a'
['a'] 'a'
[B]E 'bbcc'
['b'] 'b'
[Optional]E 'bc'
[B]E 'bc'
['b'] 'b'
[Optional]
['c'] 'c'
['c'] 'c'
The exception you were seeing stems the RecoveringParseRunner not handling the syntactic predicates in the ABC grammar correctly. I have now changed the ABC example to use the ReportingParseRunner, which doesn't suffer from this issue. The bug in the RecoveringParseRunner however hasn't been fixed yet.