Class TreeParserEx

  • All Implemented Interfaces:
    ErrorReporter
    Direct Known Subclasses:
    TreeParserBase

    public class TreeParserEx
    extends org.antlr.runtime.tree.TreeParser
    implements ErrorReporter
    The TreeParserEx 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);
     }
    This will enable handling custom error messages thrown by semantic actions.
    • Field Summary

      • Fields inherited from class org.antlr.runtime.tree.TreeParser

        DOWN, input, UP
      • Fields inherited from class org.antlr.runtime.BaseRecognizer

        DEFAULT_TOKEN_CHANNEL, HIDDEN, INITIAL_FOLLOW_STACK_SIZE, MEMO_RULE_FAILED, MEMO_RULE_UNKNOWN, NEXT_TOKEN_RULE_NAME, state
    • Constructor Summary

      Constructors 
      Constructor 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.
    • 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 object)  
      protected void checkNotNull​(org.antlr.runtime.tree.CommonTree current, java.lang.Object object, java.lang.String text)  
      protected void checkNotNull​(Where where, java.lang.Object object, 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 class org.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 class org.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 and false if there were errors.
      • where

        protected final Where where​(org.antlr.runtime.tree.CommonTree node)
      • checkNotNull

        protected final void checkNotNull​(org.antlr.runtime.tree.CommonTree current,
                                          java.lang.Object object,
                                          java.lang.String text)
                                   throws SemanticException
        Throws:
        SemanticException
      • checkNotNull

        protected final void checkNotNull​(org.antlr.runtime.tree.CommonTree current,
                                          java.lang.Object object)
                                   throws SemanticException
        Throws:
        SemanticException