org.parboiled.parserunners
Class RecoveringParseRunner<V>

java.lang.Object
  extended by org.parboiled.parserunners.BasicParseRunner<V>
      extended by org.parboiled.parserunners.RecoveringParseRunner<V>
All Implemented Interfaces:
ParseRunner<V>

public class RecoveringParseRunner<V>
extends BasicParseRunner<V>

A ParseRunner implementation that is able to recover from InvalidInputErrors 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 InvalidInputErrors in the input potentially many more runs are performed to properly report all errors and test the various recovery strategies.


Nested Class Summary
static class RecoveringParseRunner.Handler
          A MatchHandler implementation that recognizes the special Chars.RESYNC character to overcome InvalidInputErrors at the respective error indices.
 
Field Summary
 
Fields inherited from class org.parboiled.parserunners.BasicParseRunner
initialValueStackSnapshot, inputBuffer, matched, parseErrors, rootContext, rootMatcher, valueStack
 
Constructor Summary
RecoveringParseRunner(Rule rule)
          Creates a new RecoveringParseRunner instance for the given rule.
RecoveringParseRunner(Rule rule, ValueStack<V> valueStack)
          Creates a new RecoveringParseRunner instance for the given rule using the given ValueStack instance.
 
Method Summary
protected  boolean attemptRecordingMatch()
           
protected  java.lang.Character findBestSingleCharInsertion(int fixIndex)
           
protected  java.lang.Character findBestSingleCharReplacement(int fixIndex)
           
protected  boolean fixError(int fixIndex)
           
protected  MatchHandler getInnerHandler()
           
protected  void performErrorReportingRun()
           
static
<V> ParsingResult<V>
run(Rule rule, java.lang.String input)
          Create a new RecoveringParseRunner instance with the given rule and input text and returns the result of its BasicParseRunner.run(String) method invocation.
protected  boolean runRootContext()
           
protected  boolean tryFixBySingleCharDeletion(int fixIndex)
           
 
Methods inherited from class org.parboiled.parserunners.BasicParseRunner
run, run, run, runRootContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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,
                             ValueStack<V> valueStack)
Creates a new RecoveringParseRunner instance for the given rule using the given ValueStack instance.

Parameters:
rule - the parser rule
valueStack - the value stack
Method Detail

run

public static <V> ParsingResult<V> run(Rule rule,
                                       java.lang.String input)
Create a new RecoveringParseRunner instance with the given rule and input text and returns the result of its BasicParseRunner.run(String) method invocation.

Parameters:
rule - the parser rule to run
input - the input text to run on
Returns:
the ParsingResult for the parsing run

runRootContext

protected boolean runRootContext()
Overrides:
runRootContext in class BasicParseRunner<V>

attemptRecordingMatch

protected boolean attemptRecordingMatch()

performErrorReportingRun

protected void performErrorReportingRun()

getInnerHandler

protected MatchHandler getInnerHandler()

fixError

protected boolean fixError(int fixIndex)

tryFixBySingleCharDeletion

protected boolean tryFixBySingleCharDeletion(int fixIndex)

findBestSingleCharInsertion

protected java.lang.Character findBestSingleCharInsertion(int fixIndex)

findBestSingleCharReplacement

protected java.lang.Character findBestSingleCharReplacement(int fixIndex)