Package org.parboiled.parserunners
Class RecoveringParseRunner<V>
- java.lang.Object
-
- org.parboiled.parserunners.AbstractParseRunner<V>
-
- org.parboiled.parserunners.RecoveringParseRunner<V>
-
- All Implemented Interfaces:
ParseRunner<V>
public class RecoveringParseRunner<V> extends AbstractParseRunner<V>
AParseRunner
implementation that is able to recover fromInvalidInputError
s in the input and therefore report more than just the firstInvalidInputError
if the input does not conform to the rule grammar. Error recovery is done by attempting to either delete an error character, insert a potentially missing character or do both at once (which is equivalent to a one char replace) whereby this implementation is able to determine itself which of these options is the best strategy. If the parse error cannot be overcome by either deleting, inserting or replacing one character a resynchronization rule is determined and the parsing process resynchronized, so that parsing can still continue. In this way the RecoveringParseRunner is able to completely parse all input texts (This ParseRunner never returns an unmatchedParsingResult
). If the input is error free thisParseRunner
implementation will only perform one parsing run, with the same speed as theBasicParseRunner
. However, if there areInvalidInputError
s in the input potentially many more runs are performed to properly report all errors and test the various recovery strategies.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RecoveringParseRunner.TimeoutException
-
Constructor Summary
Constructors Constructor Description RecoveringParseRunner(Rule rule)
Creates a new RecoveringParseRunner instance for the given rule.RecoveringParseRunner(Rule rule, long timeoutMillis)
Creates a new RecoveringParseRunner instance for the given rule.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ParsingResult<V>
run(InputBuffer inputBuffer)
Performs the actual parse and creates a corresponding ParsingResult instance.static <V> ParsingResult<V>
run(Rule rule, String input)
Deprecated.As of 0.11.0 you should use the "regular" constructor and one of the "run" methods rather than this static method.-
Methods inherited from class org.parboiled.parserunners.AbstractParseRunner
createParsingResult, createRootContext, getParseErrors, getRootMatcher, getValueStack, resetValueStack, run, run, withParseErrors, withValueStack
-
-
-
-
Constructor Detail
-
RecoveringParseRunner
public RecoveringParseRunner(Rule rule)
Creates a new RecoveringParseRunner instance for the given rule.- Parameters:
rule
- the parser rule
-
RecoveringParseRunner
public RecoveringParseRunner(Rule rule, long timeoutMillis)
Creates a new RecoveringParseRunner instance for the given rule. A parsing run will throw a TimeoutException if it takes longer than the given number if milliseconds.- Parameters:
rule
- the parser ruletimeoutMillis
- the timeout value in milliseconds
-
-
Method Detail
-
run
@Deprecated public static <V> ParsingResult<V> run(Rule rule, String input)
Deprecated.As of 0.11.0 you should use the "regular" constructor and one of the "run" methods rather than this static method. This method will be removed in one of the coming releases.Create a new RecoveringParseRunner instance with the given rule and input text and returns the result of itsAbstractParseRunner.run(String)
method invocation.- Parameters:
rule
- the parser rule to runinput
- the input text to run on- Returns:
- the ParsingResult for the parsing run
-
run
public ParsingResult<V> run(InputBuffer inputBuffer)
Description copied from interface:ParseRunner
Performs the actual parse and creates a corresponding ParsingResult instance.- Parameters:
inputBuffer
- the inputBuffer to use- Returns:
- the ParsingResult for the run
-
-