public class RecoveringParseRunner<V> extends AbstractParseRunner<V>
ParseRunner
implementation that is able to recover from InvalidInputError
s in the input and therefore
report more than just the first InvalidInputError
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 unmatched ParsingResult
).
If the input is error free this ParseRunner
implementation will only perform one parsing run, with the same
speed as the BasicParseRunner
. However, if there are InvalidInputError
s in the input potentially
many more runs are performed to properly report all errors and test the various recovery strategies.Modifier and Type | Class and Description |
---|---|
private static class |
RecoveringParseRunner.CollectResyncActionsVisitor
This MatcherVisitor collects the minimal set of actions that has to run underneath a resyncronization sequence
in order to maintain a consistent Value Stack state.
|
private class |
RecoveringParseRunner.Handler
A
MatchHandler implementation that recognizes the special
Chars.RESYNC character to overcome InvalidInputError s at the respective
error indices. |
static class |
RecoveringParseRunner.TimeoutException |
Modifier and Type | Field and Description |
---|---|
private MutableInputBuffer |
buffer |
private InvalidInputError |
currentError |
private int |
errorIndex |
private ParsingResult<V> |
lastParsingResult |
private Matcher |
rootMatcherWithoutPTB |
private long |
startTimeStamp |
private long |
timeout |
Constructor and Description |
---|
RecoveringParseRunner(Rule rule)
Creates a new RecoveringParseRunner instance for the given rule.
|
RecoveringParseRunner(Rule rule,
long timeout)
Creates a new RecoveringParseRunner instance for the given rule.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.Character |
findBestSingleCharInsertion(int fixIndex) |
private java.lang.Character |
findBestSingleCharReplacement(int fixIndex) |
private boolean |
fixError(int fixIndex) |
private MatchHandler |
getInnerHandler() |
private void |
performFinalRun() |
private boolean |
performLocatingRun(InputBuffer inputBuffer) |
private void |
performReportingRun() |
ParsingResult<V> |
run(InputBuffer inputBuffer)
Performs the actual parse and creates a corresponding ParsingResult instance.
|
static <V> ParsingResult<V> |
run(Rule rule,
java.lang.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.
|
private boolean |
tryFixBySingleCharDeletion(int fixIndex) |
createParsingResult, createRootContext, getParseErrors, getRootMatcher, getValueStack, resetValueStack, run, run, withParseErrors, withValueStack
private final long timeout
private long startTimeStamp
private int errorIndex
private InvalidInputError currentError
private MutableInputBuffer buffer
private ParsingResult<V> lastParsingResult
private Matcher rootMatcherWithoutPTB
public RecoveringParseRunner(Rule rule)
rule
- the parser rulepublic RecoveringParseRunner(Rule rule, long timeout)
rule
- the parser ruletimeout
- the timeout value in milliseconds@Deprecated public static <V> ParsingResult<V> run(Rule rule, java.lang.String input)
AbstractParseRunner.run(String)
method invocation.rule
- the parser rule to runinput
- the input text to run onpublic ParsingResult<V> run(InputBuffer inputBuffer)
ParseRunner
inputBuffer
- the inputBuffer to useprivate boolean performLocatingRun(InputBuffer inputBuffer)
private void performReportingRun()
private void performFinalRun()
private MatchHandler getInnerHandler()
private boolean fixError(int fixIndex)
private boolean tryFixBySingleCharDeletion(int fixIndex)
private java.lang.Character findBestSingleCharInsertion(int fixIndex)
private java.lang.Character findBestSingleCharReplacement(int fixIndex)