程序包 org.antlr.tool

类 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.
    • 字段详细资料

      • MSG_CANNOT_WRITE_FILE

        public static final int MSG_CANNOT_WRITE_FILE
        另请参阅:
        常量字段值
      • MSG_CANNOT_CLOSE_FILE

        public static final int MSG_CANNOT_CLOSE_FILE
        另请参阅:
        常量字段值
      • MSG_CANNOT_FIND_TOKENS_FILE

        public static final int MSG_CANNOT_FIND_TOKENS_FILE
        另请参阅:
        常量字段值
      • MSG_ERROR_READING_TOKENS_FILE

        public static final int MSG_ERROR_READING_TOKENS_FILE
        另请参阅:
        常量字段值
      • MSG_DIR_NOT_FOUND

        public static final int MSG_DIR_NOT_FOUND
        另请参阅:
        常量字段值
      • MSG_OUTPUT_DIR_IS_FILE

        public static final int MSG_OUTPUT_DIR_IS_FILE
        另请参阅:
        常量字段值
      • MSG_CANNOT_OPEN_FILE

        public static final int MSG_CANNOT_OPEN_FILE
        另请参阅:
        常量字段值
      • MSG_FILE_AND_GRAMMAR_NAME_DIFFER

        public static final int MSG_FILE_AND_GRAMMAR_NAME_DIFFER
        另请参阅:
        常量字段值
      • MSG_FILENAME_EXTENSION_ERROR

        public static final int MSG_FILENAME_EXTENSION_ERROR
        另请参阅:
        常量字段值
      • MSG_INTERNAL_ERROR

        public static final int MSG_INTERNAL_ERROR
        另请参阅:
        常量字段值
      • MSG_INTERNAL_WARNING

        public static final int MSG_INTERNAL_WARNING
        另请参阅:
        常量字段值
      • MSG_ERROR_CREATING_ARTIFICIAL_RULE

        public static final int MSG_ERROR_CREATING_ARTIFICIAL_RULE
        另请参阅:
        常量字段值
      • MSG_TOKENS_FILE_SYNTAX_ERROR

        public static final int MSG_TOKENS_FILE_SYNTAX_ERROR
        另请参阅:
        常量字段值
      • MSG_CANNOT_GEN_DOT_FILE

        public static final int MSG_CANNOT_GEN_DOT_FILE
        另请参阅:
        常量字段值
      • MSG_BAD_AST_STRUCTURE

        public static final int MSG_BAD_AST_STRUCTURE
        另请参阅:
        常量字段值
      • MSG_BAD_ACTION_AST_STRUCTURE

        public static final int MSG_BAD_ACTION_AST_STRUCTURE
        另请参阅:
        常量字段值
      • MSG_MISSING_CODE_GEN_TEMPLATES

        public static final int MSG_MISSING_CODE_GEN_TEMPLATES
        另请参阅:
        常量字段值
      • MSG_MISSING_CYCLIC_DFA_CODE_GEN_TEMPLATES

        public static final int MSG_MISSING_CYCLIC_DFA_CODE_GEN_TEMPLATES
        另请参阅:
        常量字段值
      • MSG_CODE_GEN_TEMPLATES_INCOMPLETE

        public static final int MSG_CODE_GEN_TEMPLATES_INCOMPLETE
        另请参阅:
        常量字段值
      • MSG_CANNOT_CREATE_TARGET_GENERATOR

        public static final int MSG_CANNOT_CREATE_TARGET_GENERATOR
        另请参阅:
        常量字段值
      • MSG_STRING_TEMPLATE_ERROR

        public static final int MSG_STRING_TEMPLATE_ERROR
        另请参阅:
        常量字段值
      • MSG_SYNTAX_ERROR

        public static final int MSG_SYNTAX_ERROR
        另请参阅:
        常量字段值
      • MSG_RULE_REDEFINITION

        public static final int MSG_RULE_REDEFINITION
        另请参阅:
        常量字段值
      • MSG_LEXER_RULES_NOT_ALLOWED

        public static final int MSG_LEXER_RULES_NOT_ALLOWED
        另请参阅:
        常量字段值
      • MSG_PARSER_RULES_NOT_ALLOWED

        public static final int MSG_PARSER_RULES_NOT_ALLOWED
        另请参阅:
        常量字段值
      • MSG_CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL

        public static final int MSG_CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL
        另请参阅:
        常量字段值
      • MSG_NO_TOKEN_DEFINITION

        public static final int MSG_NO_TOKEN_DEFINITION
        另请参阅:
        常量字段值
      • MSG_UNDEFINED_RULE_REF

        public static final int MSG_UNDEFINED_RULE_REF
        另请参阅:
        常量字段值
      • MSG_LITERAL_NOT_ASSOCIATED_WITH_LEXER_RULE

        public static final int MSG_LITERAL_NOT_ASSOCIATED_WITH_LEXER_RULE
        另请参阅:
        常量字段值
      • MSG_CANNOT_ALIAS_TOKENS_IN_LEXER

        public static final int MSG_CANNOT_ALIAS_TOKENS_IN_LEXER
        另请参阅:
        常量字段值
      • MSG_ATTRIBUTE_REF_NOT_IN_RULE

        public static final int MSG_ATTRIBUTE_REF_NOT_IN_RULE
        另请参阅:
        常量字段值
      • MSG_INVALID_RULE_SCOPE_ATTRIBUTE_REF

        public static final int MSG_INVALID_RULE_SCOPE_ATTRIBUTE_REF
        另请参阅:
        常量字段值
      • MSG_UNKNOWN_ATTRIBUTE_IN_SCOPE

        public static final int MSG_UNKNOWN_ATTRIBUTE_IN_SCOPE
        另请参阅:
        常量字段值
      • MSG_UNKNOWN_SIMPLE_ATTRIBUTE

        public static final int MSG_UNKNOWN_SIMPLE_ATTRIBUTE
        另请参阅:
        常量字段值
      • MSG_INVALID_RULE_PARAMETER_REF

        public static final int MSG_INVALID_RULE_PARAMETER_REF
        另请参阅:
        常量字段值
      • MSG_UNKNOWN_RULE_ATTRIBUTE

        public static final int MSG_UNKNOWN_RULE_ATTRIBUTE
        另请参阅:
        常量字段值
      • MSG_ISOLATED_RULE_SCOPE

        public static final int MSG_ISOLATED_RULE_SCOPE
        另请参阅:
        常量字段值
      • MSG_SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE

        public static final int MSG_SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE
        另请参阅:
        常量字段值
      • MSG_LABEL_CONFLICTS_WITH_RULE

        public static final int MSG_LABEL_CONFLICTS_WITH_RULE
        另请参阅:
        常量字段值
      • MSG_LABEL_CONFLICTS_WITH_TOKEN

        public static final int MSG_LABEL_CONFLICTS_WITH_TOKEN
        另请参阅:
        常量字段值
      • MSG_LABEL_CONFLICTS_WITH_RULE_SCOPE_ATTRIBUTE

        public static final int MSG_LABEL_CONFLICTS_WITH_RULE_SCOPE_ATTRIBUTE
        另请参阅:
        常量字段值
      • MSG_LABEL_CONFLICTS_WITH_RULE_ARG_RETVAL

        public static final int MSG_LABEL_CONFLICTS_WITH_RULE_ARG_RETVAL
        另请参阅:
        常量字段值
      • MSG_ATTRIBUTE_CONFLICTS_WITH_RULE

        public static final int MSG_ATTRIBUTE_CONFLICTS_WITH_RULE
        另请参阅:
        常量字段值
      • MSG_ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL

        public static final int MSG_ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL
        另请参阅:
        常量字段值
      • MSG_LABEL_TYPE_CONFLICT

        public static final int MSG_LABEL_TYPE_CONFLICT
        另请参阅:
        常量字段值
      • MSG_ARG_RETVAL_CONFLICT

        public static final int MSG_ARG_RETVAL_CONFLICT
        另请参阅:
        常量字段值
      • MSG_NONUNIQUE_REF

        public static final int MSG_NONUNIQUE_REF
        另请参阅:
        常量字段值
      • MSG_FORWARD_ELEMENT_REF

        public static final int MSG_FORWARD_ELEMENT_REF
        另请参阅:
        常量字段值
      • MSG_MISSING_RULE_ARGS

        public static final int MSG_MISSING_RULE_ARGS
        另请参阅:
        常量字段值
      • MSG_RULE_HAS_NO_ARGS

        public static final int MSG_RULE_HAS_NO_ARGS
        另请参阅:
        常量字段值
      • MSG_ARGS_ON_TOKEN_REF

        public static final int MSG_ARGS_ON_TOKEN_REF
        另请参阅:
        常量字段值
      • MSG_RULE_REF_AMBIG_WITH_RULE_IN_ALT

        public static final int MSG_RULE_REF_AMBIG_WITH_RULE_IN_ALT
        另请参阅:
        常量字段值
      • MSG_ILLEGAL_OPTION

        public static final int MSG_ILLEGAL_OPTION
        另请参阅:
        常量字段值
      • MSG_LIST_LABEL_INVALID_UNLESS_RETVAL_STRUCT

        public static final int MSG_LIST_LABEL_INVALID_UNLESS_RETVAL_STRUCT
        另请参阅:
        常量字段值
      • MSG_UNDEFINED_TOKEN_REF_IN_REWRITE

        public static final int MSG_UNDEFINED_TOKEN_REF_IN_REWRITE
        另请参阅:
        常量字段值
      • MSG_REWRITE_ELEMENT_NOT_PRESENT_ON_LHS

        public static final int MSG_REWRITE_ELEMENT_NOT_PRESENT_ON_LHS
        另请参阅:
        常量字段值
      • MSG_UNDEFINED_LABEL_REF_IN_REWRITE

        public static final int MSG_UNDEFINED_LABEL_REF_IN_REWRITE
        另请参阅:
        常量字段值
      • MSG_NO_GRAMMAR_START_RULE

        public static final int MSG_NO_GRAMMAR_START_RULE
        另请参阅:
        常量字段值
      • MSG_EMPTY_COMPLEMENT

        public static final int MSG_EMPTY_COMPLEMENT
        另请参阅:
        常量字段值
      • MSG_UNKNOWN_DYNAMIC_SCOPE

        public static final int MSG_UNKNOWN_DYNAMIC_SCOPE
        另请参阅:
        常量字段值
      • MSG_UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE

        public static final int MSG_UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE
        另请参阅:
        常量字段值
      • MSG_ISOLATED_RULE_ATTRIBUTE

        public static final int MSG_ISOLATED_RULE_ATTRIBUTE
        另请参阅:
        常量字段值
      • MSG_INVALID_ACTION_SCOPE

        public static final int MSG_INVALID_ACTION_SCOPE
        另请参阅:
        常量字段值
      • MSG_ACTION_REDEFINITION

        public static final int MSG_ACTION_REDEFINITION
        另请参阅:
        常量字段值
      • MSG_DOUBLE_QUOTES_ILLEGAL

        public static final int MSG_DOUBLE_QUOTES_ILLEGAL
        另请参阅:
        常量字段值
      • MSG_INVALID_TEMPLATE_ACTION

        public static final int MSG_INVALID_TEMPLATE_ACTION
        另请参阅:
        常量字段值
      • MSG_MISSING_ATTRIBUTE_NAME

        public static final int MSG_MISSING_ATTRIBUTE_NAME
        另请参阅:
        常量字段值
      • MSG_ARG_INIT_VALUES_ILLEGAL

        public static final int MSG_ARG_INIT_VALUES_ILLEGAL
        另请参阅:
        常量字段值
      • MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION

        public static final int MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION
        另请参阅:
        常量字段值
      • MSG_NO_RULES

        public static final int MSG_NO_RULES
        另请参阅:
        常量字段值
      • MSG_WRITE_TO_READONLY_ATTR

        public static final int MSG_WRITE_TO_READONLY_ATTR
        另请参阅:
        常量字段值
      • MSG_MISSING_AST_TYPE_IN_TREE_GRAMMAR

        public static final int MSG_MISSING_AST_TYPE_IN_TREE_GRAMMAR
        另请参阅:
        常量字段值
      • MSG_REWRITE_FOR_MULTI_ELEMENT_ALT

        public static final int MSG_REWRITE_FOR_MULTI_ELEMENT_ALT
        另请参阅:
        常量字段值
      • MSG_RULE_INVALID_SET

        public static final int MSG_RULE_INVALID_SET
        另请参阅:
        常量字段值
      • MSG_HETERO_ILLEGAL_IN_REWRITE_ALT

        public static final int MSG_HETERO_ILLEGAL_IN_REWRITE_ALT
        另请参阅:
        常量字段值
      • MSG_NO_SUCH_GRAMMAR_SCOPE

        public static final int MSG_NO_SUCH_GRAMMAR_SCOPE
        另请参阅:
        常量字段值
      • MSG_NO_SUCH_RULE_IN_SCOPE

        public static final int MSG_NO_SUCH_RULE_IN_SCOPE
        另请参阅:
        常量字段值
      • MSG_TOKEN_ALIAS_CONFLICT

        public static final int MSG_TOKEN_ALIAS_CONFLICT
        另请参阅:
        常量字段值
      • MSG_TOKEN_ALIAS_REASSIGNMENT

        public static final int MSG_TOKEN_ALIAS_REASSIGNMENT
        另请参阅:
        常量字段值
      • MSG_TOKEN_VOCAB_IN_DELEGATE

        public static final int MSG_TOKEN_VOCAB_IN_DELEGATE
        另请参阅:
        常量字段值
      • MSG_INVALID_IMPORT

        public static final int MSG_INVALID_IMPORT
        另请参阅:
        常量字段值
      • MSG_IMPORTED_TOKENS_RULE_EMPTY

        public static final int MSG_IMPORTED_TOKENS_RULE_EMPTY
        另请参阅:
        常量字段值
      • MSG_IMPORT_NAME_CLASH

        public static final int MSG_IMPORT_NAME_CLASH
        另请参阅:
        常量字段值
      • MSG_AST_OP_WITH_NON_AST_OUTPUT_OPTION

        public static final int MSG_AST_OP_WITH_NON_AST_OUTPUT_OPTION
        另请参阅:
        常量字段值
      • MSG_AST_OP_IN_ALT_WITH_REWRITE

        public static final int MSG_AST_OP_IN_ALT_WITH_REWRITE
        另请参阅:
        常量字段值
      • MSG_WILDCARD_AS_ROOT

        public static final int MSG_WILDCARD_AS_ROOT
        另请参阅:
        常量字段值
      • MSG_CONFLICTING_OPTION_IN_TREE_FILTER

        public static final int MSG_CONFLICTING_OPTION_IN_TREE_FILTER
        另请参阅:
        常量字段值
      • MSG_ILLEGAL_OPTION_VALUE

        public static final int MSG_ILLEGAL_OPTION_VALUE
        另请参阅:
        常量字段值
      • MSG_ALL_OPS_NEED_SAME_ASSOC

        public static final int MSG_ALL_OPS_NEED_SAME_ASSOC
        另请参阅:
        常量字段值
      • MSG_RANGE_OP_ILLEGAL

        public static final int MSG_RANGE_OP_ILLEGAL
        另请参阅:
        常量字段值
      • MSG_GRAMMAR_NONDETERMINISM

        public static final int MSG_GRAMMAR_NONDETERMINISM
        另请参阅:
        常量字段值
      • MSG_UNREACHABLE_ALTS

        public static final int MSG_UNREACHABLE_ALTS
        另请参阅:
        常量字段值
      • MSG_DANGLING_STATE

        public static final int MSG_DANGLING_STATE
        另请参阅:
        常量字段值
      • MSG_INSUFFICIENT_PREDICATES

        public static final int MSG_INSUFFICIENT_PREDICATES
        另请参阅:
        常量字段值
      • MSG_DUPLICATE_SET_ENTRY

        public static final int MSG_DUPLICATE_SET_ENTRY
        另请参阅:
        常量字段值
      • MSG_ANALYSIS_ABORTED

        public static final int MSG_ANALYSIS_ABORTED
        另请参阅:
        常量字段值
      • MSG_RECURSION_OVERLOW

        public static final int MSG_RECURSION_OVERLOW
        另请参阅:
        常量字段值
      • MSG_LEFT_RECURSION

        public static final int MSG_LEFT_RECURSION
        另请参阅:
        常量字段值
      • MSG_UNREACHABLE_TOKENS

        public static final int MSG_UNREACHABLE_TOKENS
        另请参阅:
        常量字段值
      • MSG_TOKEN_NONDETERMINISM

        public static final int MSG_TOKEN_NONDETERMINISM
        另请参阅:
        常量字段值
      • MSG_LEFT_RECURSION_CYCLES

        public static final int MSG_LEFT_RECURSION_CYCLES
        另请参阅:
        常量字段值
      • MSG_NONREGULAR_DECISION

        public static final int MSG_NONREGULAR_DECISION
        另请参阅:
        常量字段值
      • MSG_CIRCULAR_DEPENDENCY

        public static final int MSG_CIRCULAR_DEPENDENCY
        另请参阅:
        常量字段值
      • MAX_MESSAGE_NUMBER

        public static final int MAX_MESSAGE_NUMBER
        另请参阅:
        常量字段值
      • 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.
    • 构造器详细资料

      • ErrorManager

        public ErrorManager()
    • 方法详细资料

      • 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<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,
                                        Token token,
                                        java.lang.Object arg,
                                        java.lang.Object arg2)
      • grammarError

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

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

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

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

        public static void grammarWarning​(int msgID,
                                          Grammar g,
                                          Token token)
      • 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...