Class TreeParserEx
- java.lang.Object
-
- org.antlr.runtime.BaseRecognizer
-
- org.antlr.runtime.tree.TreeParser
-
- ru.ispras.microtesk.translator.antlrex.TreeParserEx
-
- All Implemented Interfaces:
ErrorReporter
- Direct Known Subclasses:
TreeParserBase
public class TreeParserEx extends org.antlr.runtime.tree.TreeParser implements ErrorReporter
TheTreeParserEx
class is an extension of the standard ANTLR TreeParser class. It provides advanced error-handling facilities by overriding standard error-handling methods. This allows collecting full information about errors in a special log store.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); }
-
-
Constructor Summary
Constructors Constructor Description TreeParserEx(org.antlr.runtime.tree.TreeNodeStream input)
Creates a TreeParserEx objectTreeParserEx(org.antlr.runtime.tree.TreeNodeStream input, org.antlr.runtime.RecognizerSharedState state)
Creates a TreeParserEx object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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
isSuccessful()
Checks if parsing was successful (no errors occurred).void
raiseError(Where where, java.lang.String what)
void
raiseError(Where where, ISemanticError error)
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)
-
Methods inherited from class org.antlr.runtime.tree.TreeParser
getAncestor, getCurrentInputSymbol, getErrorHeader, getErrorMessage, getMissingSymbol, getSourceName, getTreeNodeStream, inContext, inContext, matchAny, recoverFromMismatchedToken, reset, setTreeNodeStream, traceIn, traceOut
-
Methods inherited from class org.antlr.runtime.BaseRecognizer
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
-
-
-
-
Constructor Detail
-
TreeParserEx
public TreeParserEx(org.antlr.runtime.tree.TreeNodeStream input, org.antlr.runtime.RecognizerSharedState state)
Creates a TreeParserEx object.- Parameters:
input
- A stream of AST nodes.state
- A recognizer state that is used in error recovery and can be shared among recognizers.
-
TreeParserEx
public TreeParserEx(org.antlr.runtime.tree.TreeNodeStream input)
Creates a TreeParserEx object- Parameters:
input
- A stream of AST nodes.
-
-
Method Detail
-
assignLog
public final void assignLog(LogStore log)
Assigns a log store to the tree parser.- Parameters:
log
- A log store object.
-
reportError
public final void reportError(org.antlr.runtime.RecognitionException re)
An overridden error handling function. Packs information information about and exception into a log entry object and posts it to the log store. Aimed to handle standard ANTLR recognition exception thrown by automatically generated parser code.- Overrides:
reportError
in classorg.antlr.runtime.BaseRecognizer
- Parameters:
re
- A standard ANTLR exception.
-
reportError
public final void reportError(SemanticException se)
Provides convenient handling for extended exceptions thrown by semantic actions. Post the collected information to the log store.- Parameters:
se
- A custom exception thrown by code located in semantic actions.
-
emitErrorMessage
public final void emitErrorMessage(java.lang.String errorMessage)
An overridden method of the BaseRecognizer class. Allows collecting text printed by the reportError method of the BaseRecognizer class. It is needed to pick up messages of standard RecognitionException exceptions.- Overrides:
emitErrorMessage
in classorg.antlr.runtime.BaseRecognizer
- Parameters:
errorMessage
- Error message text.
-
getErrorCount
public final int getErrorCount()
Returns the number of errors reported during parsing.- Returns:
- Number of errors.
-
resetErrorCount
public final void resetErrorCount()
Resets (sets to zero) he counter of parsing errors.
-
isSuccessful
public final boolean isSuccessful()
Checks if parsing was successful (no errors occurred).- Returns:
true
if no parsing errors were detected andfalse
if there were errors.
-
raiseError
public final void raiseError(Where where, ISemanticError error) throws SemanticException
- Specified by:
raiseError
in interfaceErrorReporter
- Throws:
SemanticException
-
raiseError
public void raiseError(Where where, java.lang.String what) throws SemanticException
- Specified by:
raiseError
in interfaceErrorReporter
- Throws:
SemanticException
-
where
protected final Where where(org.antlr.runtime.tree.CommonTree node)
-
checkNotNull
protected final void checkNotNull(Where w, java.lang.Object obj, java.lang.String text) throws SemanticException
- Throws:
SemanticException
-
checkNotNull
protected final void checkNotNull(org.antlr.runtime.tree.CommonTree current, java.lang.Object obj, java.lang.String text) throws SemanticException
- Throws:
SemanticException
-
checkNotNull
protected final void checkNotNull(org.antlr.runtime.tree.CommonTree current, java.lang.Object obj) throws SemanticException
- Throws:
SemanticException
-
-