Class ErrorManager


  • public class ErrorManager
    extends java.lang.Object
    Defines all the errors ANTLR can generator for both the tool and for issues with a grammar. Here is a list of language names: http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt Here is a list of country names: http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html I use constants not strings to identify messages as the compiler will find any errors/mismatches rather than leaving a mistyped string in the code to be found randomly in the future. Further, Intellij can do field name expansion to save me some typing. I have to map int constants to template names, however, which could introduce a mismatch. Someone could provide a .stg file that had a template name wrong. When I load the group, then, I must verify that all messages are there. This is essentially the functionality of the resource bundle stuff Java has, but I don't want to load a property file--I want to load a template group file and this is so simple, why mess with their junk. I use the default Locale as defined by java to compute a group file name in the org/antlr/tool/templates/messages dir called en_US.stg and so on. Normally we want to use the default locale, but often a message file will not exist for it so we must fall back on the US local. During initialization of this class, all errors go straight to System.err. There is no way around this. If I have not set up the error system, how can I do errors properly? For example, if the string template group file full of messages has an error, how could I print to anything but System.err? TODO: how to map locale to a file encoding for the stringtemplate group file? ST knows how to pay attention to the default encoding so it should probably just work unless a GUI sets the local to some chinese variation but System.getProperty("file.encoding") is US. Hmm... TODO: get antlr.g etc.. parsing errors to come here.
    • Field Detail

      • MSG_CANNOT_FIND_TOKENS_FILE

        public static final int MSG_CANNOT_FIND_TOKENS_FILE
        See Also:
        Constant Field Values
      • MSG_ERROR_READING_TOKENS_FILE

        public static final int MSG_ERROR_READING_TOKENS_FILE
        See Also:
        Constant Field Values
      • MSG_FILE_AND_GRAMMAR_NAME_DIFFER

        public static final int MSG_FILE_AND_GRAMMAR_NAME_DIFFER
        See Also:
        Constant Field Values
      • MSG_FILENAME_EXTENSION_ERROR

        public static final int MSG_FILENAME_EXTENSION_ERROR
        See Also:
        Constant Field Values
      • MSG_ERROR_CREATING_ARTIFICIAL_RULE

        public static final int MSG_ERROR_CREATING_ARTIFICIAL_RULE
        See Also:
        Constant Field Values
      • MSG_TOKENS_FILE_SYNTAX_ERROR

        public static final int MSG_TOKENS_FILE_SYNTAX_ERROR
        See Also:
        Constant Field Values
      • MSG_CANNOT_GEN_DOT_FILE

        public static final int MSG_CANNOT_GEN_DOT_FILE
        See Also:
        Constant Field Values
      • MSG_BAD_ACTION_AST_STRUCTURE

        public static final int MSG_BAD_ACTION_AST_STRUCTURE
        See Also:
        Constant Field Values
      • MSG_MISSING_CODE_GEN_TEMPLATES

        public static final int MSG_MISSING_CODE_GEN_TEMPLATES
        See Also:
        Constant Field Values
      • MSG_MISSING_CYCLIC_DFA_CODE_GEN_TEMPLATES

        public static final int MSG_MISSING_CYCLIC_DFA_CODE_GEN_TEMPLATES
        See Also:
        Constant Field Values
      • MSG_CODE_GEN_TEMPLATES_INCOMPLETE

        public static final int MSG_CODE_GEN_TEMPLATES_INCOMPLETE
        See Also:
        Constant Field Values
      • MSG_CANNOT_CREATE_TARGET_GENERATOR

        public static final int MSG_CANNOT_CREATE_TARGET_GENERATOR
        See Also:
        Constant Field Values
      • MSG_STRING_TEMPLATE_ERROR

        public static final int MSG_STRING_TEMPLATE_ERROR
        See Also:
        Constant Field Values
      • MSG_LEXER_RULES_NOT_ALLOWED

        public static final int MSG_LEXER_RULES_NOT_ALLOWED
        See Also:
        Constant Field Values
      • MSG_PARSER_RULES_NOT_ALLOWED

        public static final int MSG_PARSER_RULES_NOT_ALLOWED
        See Also:
        Constant Field Values
      • MSG_CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL

        public static final int MSG_CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL
        See Also:
        Constant Field Values
      • MSG_NO_TOKEN_DEFINITION

        public static final int MSG_NO_TOKEN_DEFINITION
        See Also:
        Constant Field Values
      • MSG_LITERAL_NOT_ASSOCIATED_WITH_LEXER_RULE

        public static final int MSG_LITERAL_NOT_ASSOCIATED_WITH_LEXER_RULE
        See Also:
        Constant Field Values
      • MSG_CANNOT_ALIAS_TOKENS_IN_LEXER

        public static final int MSG_CANNOT_ALIAS_TOKENS_IN_LEXER
        See Also:
        Constant Field Values
      • MSG_ATTRIBUTE_REF_NOT_IN_RULE

        public static final int MSG_ATTRIBUTE_REF_NOT_IN_RULE
        See Also:
        Constant Field Values
      • MSG_INVALID_RULE_SCOPE_ATTRIBUTE_REF

        public static final int MSG_INVALID_RULE_SCOPE_ATTRIBUTE_REF
        See Also:
        Constant Field Values
      • MSG_UNKNOWN_ATTRIBUTE_IN_SCOPE

        public static final int MSG_UNKNOWN_ATTRIBUTE_IN_SCOPE
        See Also:
        Constant Field Values
      • MSG_UNKNOWN_SIMPLE_ATTRIBUTE

        public static final int MSG_UNKNOWN_SIMPLE_ATTRIBUTE
        See Also:
        Constant Field Values
      • MSG_INVALID_RULE_PARAMETER_REF

        public static final int MSG_INVALID_RULE_PARAMETER_REF
        See Also:
        Constant Field Values
      • MSG_UNKNOWN_RULE_ATTRIBUTE

        public static final int MSG_UNKNOWN_RULE_ATTRIBUTE
        See Also:
        Constant Field Values
      • MSG_ISOLATED_RULE_SCOPE

        public static final int MSG_ISOLATED_RULE_SCOPE
        See Also:
        Constant Field Values
      • MSG_SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE

        public static final int MSG_SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE
        See Also:
        Constant Field Values
      • MSG_LABEL_CONFLICTS_WITH_RULE

        public static final int MSG_LABEL_CONFLICTS_WITH_RULE
        See Also:
        Constant Field Values
      • MSG_LABEL_CONFLICTS_WITH_TOKEN

        public static final int MSG_LABEL_CONFLICTS_WITH_TOKEN
        See Also:
        Constant Field Values
      • MSG_LABEL_CONFLICTS_WITH_RULE_SCOPE_ATTRIBUTE

        public static final int MSG_LABEL_CONFLICTS_WITH_RULE_SCOPE_ATTRIBUTE
        See Also:
        Constant Field Values
      • MSG_LABEL_CONFLICTS_WITH_RULE_ARG_RETVAL

        public static final int MSG_LABEL_CONFLICTS_WITH_RULE_ARG_RETVAL
        See Also:
        Constant Field Values
      • MSG_ATTRIBUTE_CONFLICTS_WITH_RULE

        public static final int MSG_ATTRIBUTE_CONFLICTS_WITH_RULE
        See Also:
        Constant Field Values
      • MSG_ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL

        public static final int MSG_ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL
        See Also:
        Constant Field Values
      • MSG_LABEL_TYPE_CONFLICT

        public static final int MSG_LABEL_TYPE_CONFLICT
        See Also:
        Constant Field Values
      • MSG_ARG_RETVAL_CONFLICT

        public static final int MSG_ARG_RETVAL_CONFLICT
        See Also:
        Constant Field Values
      • MSG_FORWARD_ELEMENT_REF

        public static final int MSG_FORWARD_ELEMENT_REF
        See Also:
        Constant Field Values
      • MSG_RULE_REF_AMBIG_WITH_RULE_IN_ALT

        public static final int MSG_RULE_REF_AMBIG_WITH_RULE_IN_ALT
        See Also:
        Constant Field Values
      • MSG_LIST_LABEL_INVALID_UNLESS_RETVAL_STRUCT

        public static final int MSG_LIST_LABEL_INVALID_UNLESS_RETVAL_STRUCT
        See Also:
        Constant Field Values
      • MSG_UNDEFINED_TOKEN_REF_IN_REWRITE

        public static final int MSG_UNDEFINED_TOKEN_REF_IN_REWRITE
        See Also:
        Constant Field Values
      • MSG_REWRITE_ELEMENT_NOT_PRESENT_ON_LHS

        public static final int MSG_REWRITE_ELEMENT_NOT_PRESENT_ON_LHS
        See Also:
        Constant Field Values
      • MSG_UNDEFINED_LABEL_REF_IN_REWRITE

        public static final int MSG_UNDEFINED_LABEL_REF_IN_REWRITE
        See Also:
        Constant Field Values
      • MSG_NO_GRAMMAR_START_RULE

        public static final int MSG_NO_GRAMMAR_START_RULE
        See Also:
        Constant Field Values
      • MSG_UNKNOWN_DYNAMIC_SCOPE

        public static final int MSG_UNKNOWN_DYNAMIC_SCOPE
        See Also:
        Constant Field Values
      • MSG_UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE

        public static final int MSG_UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE
        See Also:
        Constant Field Values
      • MSG_ISOLATED_RULE_ATTRIBUTE

        public static final int MSG_ISOLATED_RULE_ATTRIBUTE
        See Also:
        Constant Field Values
      • MSG_INVALID_ACTION_SCOPE

        public static final int MSG_INVALID_ACTION_SCOPE
        See Also:
        Constant Field Values
      • MSG_ACTION_REDEFINITION

        public static final int MSG_ACTION_REDEFINITION
        See Also:
        Constant Field Values
      • MSG_DOUBLE_QUOTES_ILLEGAL

        public static final int MSG_DOUBLE_QUOTES_ILLEGAL
        See Also:
        Constant Field Values
      • MSG_INVALID_TEMPLATE_ACTION

        public static final int MSG_INVALID_TEMPLATE_ACTION
        See Also:
        Constant Field Values
      • MSG_MISSING_ATTRIBUTE_NAME

        public static final int MSG_MISSING_ATTRIBUTE_NAME
        See Also:
        Constant Field Values
      • MSG_ARG_INIT_VALUES_ILLEGAL

        public static final int MSG_ARG_INIT_VALUES_ILLEGAL
        See Also:
        Constant Field Values
      • MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION

        public static final int MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION
        See Also:
        Constant Field Values
      • MSG_WRITE_TO_READONLY_ATTR

        public static final int MSG_WRITE_TO_READONLY_ATTR
        See Also:
        Constant Field Values
      • MSG_MISSING_AST_TYPE_IN_TREE_GRAMMAR

        public static final int MSG_MISSING_AST_TYPE_IN_TREE_GRAMMAR
        See Also:
        Constant Field Values
      • MSG_REWRITE_FOR_MULTI_ELEMENT_ALT

        public static final int MSG_REWRITE_FOR_MULTI_ELEMENT_ALT
        See Also:
        Constant Field Values
      • MSG_HETERO_ILLEGAL_IN_REWRITE_ALT

        public static final int MSG_HETERO_ILLEGAL_IN_REWRITE_ALT
        See Also:
        Constant Field Values
      • MSG_NO_SUCH_GRAMMAR_SCOPE

        public static final int MSG_NO_SUCH_GRAMMAR_SCOPE
        See Also:
        Constant Field Values
      • MSG_NO_SUCH_RULE_IN_SCOPE

        public static final int MSG_NO_SUCH_RULE_IN_SCOPE
        See Also:
        Constant Field Values
      • MSG_TOKEN_ALIAS_CONFLICT

        public static final int MSG_TOKEN_ALIAS_CONFLICT
        See Also:
        Constant Field Values
      • MSG_TOKEN_ALIAS_REASSIGNMENT

        public static final int MSG_TOKEN_ALIAS_REASSIGNMENT
        See Also:
        Constant Field Values
      • MSG_TOKEN_VOCAB_IN_DELEGATE

        public static final int MSG_TOKEN_VOCAB_IN_DELEGATE
        See Also:
        Constant Field Values
      • MSG_IMPORTED_TOKENS_RULE_EMPTY

        public static final int MSG_IMPORTED_TOKENS_RULE_EMPTY
        See Also:
        Constant Field Values
      • MSG_AST_OP_WITH_NON_AST_OUTPUT_OPTION

        public static final int MSG_AST_OP_WITH_NON_AST_OUTPUT_OPTION
        See Also:
        Constant Field Values
      • MSG_AST_OP_IN_ALT_WITH_REWRITE

        public static final int MSG_AST_OP_IN_ALT_WITH_REWRITE
        See Also:
        Constant Field Values
      • MSG_CONFLICTING_OPTION_IN_TREE_FILTER

        public static final int MSG_CONFLICTING_OPTION_IN_TREE_FILTER
        See Also:
        Constant Field Values
      • MSG_ILLEGAL_OPTION_VALUE

        public static final int MSG_ILLEGAL_OPTION_VALUE
        See Also:
        Constant Field Values
      • MSG_ALL_OPS_NEED_SAME_ASSOC

        public static final int MSG_ALL_OPS_NEED_SAME_ASSOC
        See Also:
        Constant Field Values
      • MSG_GRAMMAR_NONDETERMINISM

        public static final int MSG_GRAMMAR_NONDETERMINISM
        See Also:
        Constant Field Values
      • MSG_INSUFFICIENT_PREDICATES

        public static final int MSG_INSUFFICIENT_PREDICATES
        See Also:
        Constant Field Values
      • MSG_DUPLICATE_SET_ENTRY

        public static final int MSG_DUPLICATE_SET_ENTRY
        See Also:
        Constant Field Values
      • MSG_TOKEN_NONDETERMINISM

        public static final int MSG_TOKEN_NONDETERMINISM
        See Also:
        Constant Field Values
      • MSG_LEFT_RECURSION_CYCLES

        public static final int MSG_LEFT_RECURSION_CYCLES
        See Also:
        Constant Field Values
      • MSG_NONREGULAR_DECISION

        public static final int MSG_NONREGULAR_DECISION
        See Also:
        Constant Field Values
      • MSG_CIRCULAR_DEPENDENCY

        public static final int MSG_CIRCULAR_DEPENDENCY
        See Also:
        Constant Field Values
      • ERRORS_FORCING_NO_ANALYSIS

        public static final BitSet ERRORS_FORCING_NO_ANALYSIS
        Do not do perform analysis if one of these happens
      • ERRORS_FORCING_NO_CODEGEN

        public static final BitSet ERRORS_FORCING_NO_CODEGEN
        Do not do code gen if one of these happens
      • emitSingleError

        public static final java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> emitSingleError
        Only one error can be emitted for any entry in this table. Map<String,Set> where the key is a method name like danglingState. The set is whatever that method accepts or derives like a DFA.
    • Constructor Detail

      • ErrorManager

        public ErrorManager()
    • Method Detail

      • getSTErrorListener

        public static org.stringtemplate.v4.STErrorListener getSTErrorListener()
      • setLocale

        public static void setLocale​(java.util.Locale locale)
        We really only need a single locale for entire running ANTLR code in a single VM. Only pay attention to the language, not the country so that French Canadians and French Frenchies all get the same template file, fr.stg. Just easier this way.
      • setFormat

        public static void setFormat​(java.lang.String formatName)
        The format gets reset either from the Tool if the user supplied a command line option to that effect Otherwise we just use the default "antlr".
      • setErrorListener

        public static void setErrorListener​(ANTLRErrorListener listener)
        In general, you'll want all errors to go to a single spot. However, in a GUI, you might have two frames up with two different grammars. Two threads might launch to process the grammars--you would want errors to go to different objects depending on the thread. I store a single listener per thread.
      • removeErrorListener

        public static void removeErrorListener()
      • setTool

        public static void setTool​(Tool tool)
      • getMessage

        public static org.stringtemplate.v4.ST getMessage​(int msgID)
        Given a message ID, return a ST that somebody can fill with data. We need to convert the int ID to the name of a template in the messages ST group.
      • getMessageType

        public static java.lang.String getMessageType​(int msgID)
      • getLocationFormat

        public static org.stringtemplate.v4.ST getLocationFormat()
        Return a ST that refers to the current format used for emitting messages.
      • getReportFormat

        public static org.stringtemplate.v4.ST getReportFormat()
      • getMessageFormat

        public static org.stringtemplate.v4.ST getMessageFormat()
      • formatWantsSingleLineMessage

        public static boolean formatWantsSingleLineMessage()
      • getNumErrors

        public static int getNumErrors()
      • resetErrorState

        public static void resetErrorState()
      • info

        public static void info​(java.lang.String msg)
      • error

        public static void error​(int msgID)
      • error

        public static void error​(int msgID,
                                 java.lang.Throwable e)
      • error

        public static void error​(int msgID,
                                 java.lang.Object arg)
      • error

        public static void error​(int msgID,
                                 java.lang.Object arg,
                                 java.lang.Object arg2)
      • error

        public static void error​(int msgID,
                                 java.lang.Object arg,
                                 java.lang.Throwable e)
      • warning

        public static void warning​(int msgID,
                                   java.lang.Object arg)
      • analysisAborted

        public static void analysisAborted​(DecisionProbe probe)
      • unreachableAlts

        public static void unreachableAlts​(DecisionProbe probe,
                                           java.util.List<java.lang.Integer> alts)
      • insufficientPredicates

        public static void insufficientPredicates​(DecisionProbe probe,
                                                  DFAState d,
                                                  java.util.Map<java.lang.Integer,​java.util.Set<org.antlr.runtime.Token>> altToUncoveredLocations)
      • nonLLStarDecision

        public static void nonLLStarDecision​(DecisionProbe probe)
      • recursionOverflow

        public static void recursionOverflow​(DecisionProbe probe,
                                             DFAState sampleBadState,
                                             int alt,
                                             java.util.Collection<java.lang.String> targetRules,
                                             java.util.Collection<? extends java.util.Collection<? extends NFAState>> callSiteStates)
      • leftRecursionCycles

        public static void leftRecursionCycles​(java.util.Collection<? extends java.util.Set<? extends Rule>> cycles)
      • grammarError

        public static void grammarError​(int msgID,
                                        Grammar g,
                                        org.antlr.runtime.Token token,
                                        java.lang.Object arg,
                                        java.lang.Object arg2)
      • grammarError

        public static void grammarError​(int msgID,
                                        Grammar g,
                                        org.antlr.runtime.Token token,
                                        java.lang.Object arg)
      • grammarError

        public static void grammarError​(int msgID,
                                        Grammar g,
                                        org.antlr.runtime.Token token)
      • grammarWarning

        public static void grammarWarning​(int msgID,
                                          Grammar g,
                                          org.antlr.runtime.Token token,
                                          java.lang.Object arg,
                                          java.lang.Object arg2)
      • grammarWarning

        public static void grammarWarning​(int msgID,
                                          Grammar g,
                                          org.antlr.runtime.Token token,
                                          java.lang.Object arg)
      • grammarWarning

        public static void grammarWarning​(int msgID,
                                          Grammar g,
                                          org.antlr.runtime.Token token)
      • syntaxError

        public static void syntaxError​(int msgID,
                                       Grammar grammar,
                                       org.antlr.runtime.Token token,
                                       java.lang.Object arg,
                                       org.antlr.runtime.RecognitionException re)
      • internalError

        public static void internalError​(java.lang.Object error,
                                         java.lang.Throwable e)
      • internalError

        public static void internalError​(java.lang.Object error)
      • doNotAttemptAnalysis

        public static boolean doNotAttemptAnalysis()
      • doNotAttemptCodeGen

        public static boolean doNotAttemptCodeGen()
      • assertTrue

        public static void assertTrue​(boolean condition,
                                      java.lang.String message)
      • initIdToMessageNameMapping

        protected static boolean initIdToMessageNameMapping()
      • verifyMessages

        protected static boolean verifyMessages()
        Use reflection to find list of MSG_ fields and then verify a template exists for each one from the locale's group.
      • verifyFormat

        protected static boolean verifyFormat()
        Verify the message format template group
      • panic

        public static void panic()
        I *think* this will allow Tool subclasses to exit gracefully for GUIs etc...