public class TreeParserEx extends org.antlr.runtime.tree.TreeParser implements ErrorReporter
To enable the feature in your implementation, inherit specify TreeParserEx as a base class for you tree parser class (in a grammar file or in your code) add the following code to the top of your tree parser grammar file:
@
rulecatch{
catch(SemanticException se) {
reportError(se);
recover(input,se);
}
catch (RecognitionException re) { // Default behavior
reportError(re);
recover(input,re);
}
This will enable handling custom error messages thrown by semantic actions.Constructor and Description |
---|
TreeParserEx(org.antlr.runtime.tree.TreeNodeStream input)
Creates a TreeParserEx object
|
TreeParserEx(org.antlr.runtime.tree.TreeNodeStream input,
org.antlr.runtime.RecognizerSharedState state)
Creates a TreeParserEx object.
|
Modifier and Type | Method and Description |
---|---|
void |
assignLog(LogStore log)
Assigns a log store to the tree parser.
|
protected void |
checkNotNull(org.antlr.runtime.tree.CommonTree current,
java.lang.Object obj) |
protected void |
checkNotNull(org.antlr.runtime.tree.CommonTree current,
java.lang.Object obj,
java.lang.String text) |
protected void |
checkNotNull(Where w,
java.lang.Object obj,
java.lang.String text) |
void |
emitErrorMessage(java.lang.String errorMessage)
An overridden method of the BaseRecognizer class.
|
int |
getErrorCount()
Returns the number of errors reported during parsing.
|
boolean |
isCorrect()
Checks if parsing was successful (no errors occurred).
|
void |
raiseError(Where where,
ISemanticError error) |
void |
raiseError(Where where,
java.lang.String what) |
void |
reportError(org.antlr.runtime.RecognitionException re)
An overridden error handling function.
|
void |
reportError(SemanticException se)
Provides convenient handling for extended exceptions thrown by semantic actions.
|
void |
resetErrorCount()
Resets (sets to zero) he counter of parsing errors.
|
protected Where |
where(org.antlr.runtime.tree.CommonTree node) |
getAncestor, getCurrentInputSymbol, getErrorHeader, getErrorMessage, getMissingSymbol, getSourceName, getTreeNodeStream, inContext, inContext, matchAny, recoverFromMismatchedToken, reset, setTreeNodeStream, traceIn, traceOut
alreadyParsedRule, beginResync, combineFollows, computeContextSensitiveRuleFOLLOW, computeErrorRecoverySet, consumeUntil, consumeUntil, displayRecognitionError, endResync, failed, getBacktrackingLevel, getGrammarFileName, getNumberOfSyntaxErrors, getRuleInvocationStack, getRuleInvocationStack, getRuleMemoization, getRuleMemoizationCacheSize, getTokenErrorDisplay, getTokenNames, match, memoize, mismatchIsMissingToken, mismatchIsUnwantedToken, pushFollow, recover, recoverFromMismatchedSet, setBacktrackingLevel, toStrings, traceIn, traceOut
public TreeParserEx(org.antlr.runtime.tree.TreeNodeStream input, org.antlr.runtime.RecognizerSharedState state)
input
- A stream of AST nodes.state
- A recognizer state that is used in error recovery and can be shared among
recognizers.public TreeParserEx(org.antlr.runtime.tree.TreeNodeStream input)
input
- A stream of AST nodes.public final void assignLog(LogStore log)
log
- A log store object.public final void reportError(org.antlr.runtime.RecognitionException re)
reportError
in class org.antlr.runtime.BaseRecognizer
re
- A standard ANTLR exception.public final void reportError(SemanticException se)
se
- A custom exception thrown by code located in semantic actions.public final void emitErrorMessage(java.lang.String errorMessage)
emitErrorMessage
in class org.antlr.runtime.BaseRecognizer
errorMessage
- Error message text.public final int getErrorCount()
public final void resetErrorCount()
public final boolean isCorrect()
true
if no parsing errors were detected and false
if there were errors.public final void raiseError(Where where, ISemanticError error) throws SemanticException
raiseError
in interface ErrorReporter
SemanticException
public void raiseError(Where where, java.lang.String what) throws SemanticException
raiseError
in interface ErrorReporter
SemanticException
protected final Where where(org.antlr.runtime.tree.CommonTree node)
protected final void checkNotNull(Where w, java.lang.Object obj, java.lang.String text) throws SemanticException
SemanticException
protected final void checkNotNull(org.antlr.runtime.tree.CommonTree current, java.lang.Object obj, java.lang.String text) throws SemanticException
SemanticException
protected final void checkNotNull(org.antlr.runtime.tree.CommonTree current, java.lang.Object obj) throws SemanticException
SemanticException