diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java index 19b3f9a79..95ffec4bc 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java @@ -131,7 +131,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { assoc = ASSOC.left; } else { - tool.errMgr.toolError(ErrorType.ILLEGAL_OPTION_VALUE, t.getOptionAST("assoc").getToken(), "assoc", assoc); + tool.errMgr.grammarError(ErrorType.ILLEGAL_OPTION_VALUE, t.g.fileName, t.getOptionAST("assoc").getToken(), "assoc", assoc); } } } diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java index 60b060c4d..2e713f78d 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java @@ -218,9 +218,9 @@ public class LeftRecursiveRuleTransformer { } catch (Exception e) { tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, + e, ruleStart, - "error parsing rule created during left-recursion detection: "+ruleText, - e); + "error parsing rule created during left-recursion detection: "+ruleText); } return null; } diff --git a/tool/src/org/antlr/v4/tool/ErrorManager.java b/tool/src/org/antlr/v4/tool/ErrorManager.java index 2439c1d91..01bf74bb2 100644 --- a/tool/src/org/antlr/v4/tool/ErrorManager.java +++ b/tool/src/org/antlr/v4/tool/ErrorManager.java @@ -164,15 +164,11 @@ public class ErrorManager { * @param args The arguments to pass to the StringTemplate */ public void toolError(ErrorType errorType, Object... args) { - toolError(errorType, null, Token.INVALID_TOKEN, args); + toolError(errorType, null, args); } - public void toolError(ErrorType errorType, Token offendingToken, Object... args) { - toolError(errorType, null, offendingToken, args); - } - - public void toolError(ErrorType errorType, Throwable e, Token offendingToken, Object... args) { - ToolMessage msg = new ToolMessage(errorType, e, offendingToken, args); + public void toolError(ErrorType errorType, Throwable e, Object... args) { + ToolMessage msg = new ToolMessage(errorType, e, args); emit(errorType, msg); } diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index de4dec200..2f2a1953c 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -50,27 +50,27 @@ public enum ErrorType { /** * Compiler Error 1. * - *
cannot write file 'filename': reason
+ *cannot write file filename: reason
*/ - CANNOT_WRITE_FILE(1, "cannot write file 'unknown command-line option 'option'
+ *unknown command-line option option
*/ - INVALID_CMDLINE_ARG(2, "unknown command-line option 'cannot find tokens file 'filename'
+ *cannot find tokens file filename
*/ - CANNOT_FIND_TOKENS_FILE(3, "cannot find tokens file 'cannot find tokens file 'filename': reason
+ *cannot find tokens file filename: reason
*/ - ERROR_READING_TOKENS_FILE(4, "cannot find tokens file '- * grammar name 'name' and file name 'filename' differ
+ * grammar name name and file name filename differ */ - FILE_AND_GRAMMAR_NAME_DIFFER(8, "grammar name 'invalid {@code -Dname=value} syntax: 'syntax'
+ *invalid {@code -Dname=value} syntax: syntax
*/ - BAD_OPTION_SET_SYNTAX(9, "invalid -Dname=value syntax: 'warning treated as error
*/ WARNING_TREATED_AS_ERROR(10, "warning treated as error", ErrorSeverity.ERROR_ONE_OFF), + /** + * Compiler Error 11. + * + *cannot find tokens file filename: reason
+ */ + ERROR_READING_IMPORTED_GRAMMAR(11, "error reading imported grammar- * ANTLR cannot generate 'language' code as of version + * ANTLR cannot generate language code as of version * version
*/ - CANNOT_CREATE_TARGET_GENERATOR(31, "ANTLR cannot generate- * code generation template 'template' has missing, misnamed, or - * incomplete arg list; missing 'field'
+ * code generation template template has missing, misnamed, or + * incomplete arg list; missing field */ - CODE_TEMPLATE_ARG_ISSUE(32, "code generation template 'missing code generation template 'template'
+ *missing code generation template template
*/ - CODE_GEN_TEMPLATES_INCOMPLETE(33, "missing code generation template '- * no mapping to template name for output model class 'class'
+ * no mapping to template name for output model class class */ - NO_MODEL_TO_TEMPLATE_MAPPING(34, "no mapping to template name for output model class 'rule 'rule' redefinition; previous at line line
+ *rule rule redefinition; previous at line line
*/ - RULE_REDEFINITION(51, "rule 'lexer rule 'rule' not allowed in parser
+ *lexer rule rule not allowed in parser
*/ - LEXER_RULES_NOT_ALLOWED(52, "lexer rule 'parser rule 'rule' not allowed in lexer
+ *parser rule rule not allowed in lexer
*/ - PARSER_RULES_NOT_ALLOWED(53, "parser rule '- * reference to undefined rule 'rule' in non-local ref - * 'reference'
+ * reference to undefined rule rule in non-local ref + * reference */ - UNDEFINED_RULE_IN_NONLOCAL_REF(57, "reference to undefined rule '- * unknown attribute reference 'attribute' in - * 'expression'
+ * unknown attribute reference attribute in + * expression */ - UNKNOWN_SIMPLE_ATTRIBUTE(63, "unknown attribute reference '- * parameter 'parameter' of rule 'rule' is not accessible + * parameter parameter of rule rule is not accessible * in this scope: expression
*/ - INVALID_RULE_PARAMETER_REF(64, "parameter '- * unknown attribute 'attribute' for rule 'rule' in - * 'expression'
+ * unknown attribute attribute for rule rule in + * expression */ - UNKNOWN_RULE_ATTRIBUTE(65, "unknown attribute '- * attribute 'attribute' isn't a valid property in - * 'expression'
+ * attribute attribute isn't a valid property in + * expression */ - UNKNOWN_ATTRIBUTE_IN_SCOPE(66, "attribute '- * missing attribute access on rule reference 'rule' in - * 'expression'
+ * missing attribute access on rule reference rule in + * expression */ - ISOLATED_RULE_REF(67, "missing attribute access on rule reference 'label 'label' conflicts with rule with same name
+ *label label conflicts with rule with same name
*/ - LABEL_CONFLICTS_WITH_RULE(69, "label 'label 'label' conflicts with token with same name
+ *label label conflicts with token with same name
*/ - LABEL_CONFLICTS_WITH_TOKEN(70, "label 'label 'label' conflicts with parameter with same name
+ *label label conflicts with parameter with same name
*/ - LABEL_CONFLICTS_WITH_ARG(72, "label 'label 'label' conflicts with return value with same name
+ *label label conflicts with return value with same name
*/ - LABEL_CONFLICTS_WITH_RETVAL(73, "label 'label 'label' conflicts with local with same name
+ *label label conflicts with local with same name
*/ - LABEL_CONFLICTS_WITH_LOCAL(74, "label '- * label 'label' type mismatch with previous definition: + * label label type mismatch with previous definition: * message
*/ - LABEL_TYPE_CONFLICT(75, "label '- * return value 'name' conflicts with parameter with same name
+ * return value name conflicts with parameter with same name */ - RETVAL_CONFLICTS_WITH_ARG(76, "return value 'rule 'rule' has no defined parameters
+ *rule rule has no defined parameters
*/ - RULE_HAS_NO_ARGS(80, "rule 'unsupported option 'option'
+ *unsupported option option
*/ - ILLEGAL_OPTION(83, "unsupported option 'unsupported option value 'name=value'
+ *unsupported option value name=value
*/ - ILLEGAL_OPTION_VALUE(84, "unsupported option value 'redefinition of 'action' action
+ *redefinition of action action
*/ - ACTION_REDEFINITION(94, "redefinition of 'This error may take any of the following forms.
* *rule 'rule' is not defined in grammar 'grammar'
+ *rule rule is not defined in grammar grammar
*/ - NO_SUCH_RULE_IN_SCOPE(106, "rule 'token name 'Token' is already defined
+ *token name Token is already defined
*/ - TOKEN_NAME_REASSIGNMENT(108, "token name 'options ignored in imported grammar 'grammar'
+ *options ignored in imported grammar grammar
*/ - OPTIONS_IN_DELEGATE(109, "options ignored in imported grammar '- * can't find or load grammar 'grammar' from - * 'filename'
+ * can't find or load grammar grammar from + * filename */ - CANNOT_FIND_IMPORTED_GRAMMAR(110, "can't find or load grammar '- * grammartype grammar 'grammar1' cannot import - * grammartype grammar 'grammar2'
+ * grammartype grammar grammar1 cannot import + * grammartype grammar grammar2 */ - INVALID_IMPORT(111, "- * grammartype grammar 'grammar1' and imported - * grammartype grammar 'grammar2' both generate - * 'recognizer'
+ * grammartype grammar grammar1 and imported + * grammartype grammar grammar2 both generate + * recognizer */ - IMPORT_NAME_CLASH(113, "cannot find tokens file filename
+ */ + CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(160, "cannot find tokens file- * all operators of alt 'alt' of left-recursive rule must have same + * all operators of alt alt of left-recursive rule must have same * associativity
*/ - ALL_OPS_NEED_SAME_ASSOC(118, "all operators of alt 'rule 'rule': must label all alternatives or none
+ *rule rule: must label all alternatives or none
*/ - RULE_WITH_TOO_FEW_ALT_LABELS(122, "rule '- * rule alt label 'label' redefined in rule 'rule1', - * originally in rule 'rule2'
+ * rule alt label label redefined in rule rule1, + * originally in rule rule2 */ - ALT_LABEL_REDEF(123, "rule alt label '- * rule alt label 'label' conflicts with rule 'rule'
+ * rule alt label label conflicts with rule rule */ - ALT_LABEL_CONFLICTS_WITH_RULE(124, "rule alt label 'implicit definition of token 'Token' in parser
+ *implicit definition of token Token in parser
*/ - IMPLICIT_TOKEN_DEFINITION(125, "implicit definition of token 'label 'label' assigned to a block which is not a set
+ *label label assigned to a block which is not a set
*/ - LABEL_BLOCK_NOT_A_SET(130, "label '- * action in lexer rule 'rule' must be last element of single + * action in lexer rule rule must be last element of single * outermost alt
* * @deprecated This error is no longer issued by ANTLR 4.2. */ @Deprecated - LEXER_ACTION_PLACEMENT_ISSUE(132, "action in lexer rule '- * {@code ->command} in lexer rule 'rule' must be last element of + * {@code ->command} in lexer rule rule must be last element of * single outermost alt
*/ - LEXER_COMMAND_PLACEMENT_ISSUE(133, "->command in lexer rule '- * symbol 'symbol' conflicts with generated code in target language + * symbol symbol conflicts with generated code in target language * or runtime
* ** Note: This error has the same number as the unrelated error * {@link #UNSUPPORTED_REFERENCE_IN_LEXER_SET}.
*/ - USE_OF_BAD_WORD(134, "symbol 'rule reference 'rule' is not currently supported in a set
+ *rule reference rule is not currently supported in a set
* ** Note: This error has the same number as the unrelated error * {@link #USE_OF_BAD_WORD}.
*/ - UNSUPPORTED_REFERENCE_IN_LEXER_SET(134, "rule reference 'cannot assign a value to list label 'label'
+ *cannot assign a value to list label label
*/ - ASSIGNMENT_TO_LIST_LABEL(135, "cannot assign a value to list label 'return value 'name' conflicts with rule with same name
+ *return value name conflicts with rule with same name
*/ - RETVAL_CONFLICTS_WITH_RULE(136, "return value 'return value 'name' conflicts with token with same name
+ *return value name conflicts with token with same name
*/ - RETVAL_CONFLICTS_WITH_TOKEN(137, "return value 'parameter 'parameter' conflicts with rule with same name
+ *parameter parameter conflicts with rule with same name
*/ - ARG_CONFLICTS_WITH_RULE(138, "parameter 'parameter 'parameter' conflicts with token with same name
+ *parameter parameter conflicts with token with same name
*/ - ARG_CONFLICTS_WITH_TOKEN(139, "parameter 'local 'local' conflicts with rule with same name
+ *local local conflicts with rule with same name
*/ - LOCAL_CONFLICTS_WITH_RULE(140, "local 'local 'local' conflicts with rule token same name
+ *local local conflicts with rule token same name
*/ - LOCAL_CONFLICTS_WITH_TOKEN(141, "local 'local 'local' conflicts with parameter with same name
+ *local local conflicts with parameter with same name
*/ - LOCAL_CONFLICTS_WITH_ARG(142, "local 'local 'local' conflicts with return value with same name
+ *local local conflicts with return value with same name
*/ - LOCAL_CONFLICTS_WITH_RETVAL(143, "local '- * lexer mode 'mode' must contain at least one non-fragment + * lexer mode mode must contain at least one non-fragment * rule
* ** Every lexer mode must contain at least one rule which is not declared * with the {@code fragment} modifier.
*/ - MODE_WITHOUT_RULES(145, "lexer mode 'non-fragment lexer rule 'rule' can match the empty string
+ *non-fragment lexer rule rule can match the empty string
* *All non-fragment lexer rules must match at least one character.
* @@ -630,12 +642,12 @@ public enum ErrorType { * Whitespace : [ \t]*; // error 146 * */ - EPSILON_TOKEN(146, "non-fragment lexer rule '- * left recursive rule 'rule' must contain an alternative which is + * left recursive rule rule must contain an alternative which is * not left recursive
* *Left-recursive rules must contain at least one alternative which is not
@@ -650,12 +662,12 @@ public enum ErrorType {
* ;
*
*/
- NO_NON_LR_ALTS(147, "left recursive rule '
- * left recursive rule 'rule' contains a left recursive alternative
+ * left recursive rule rule contains a left recursive alternative
* which can be followed by the empty string In left-recursive rules, all left-recursive alternatives must match at
@@ -670,12 +682,12 @@ public enum ErrorType {
* ;
*
*/
- EPSILON_LR_FOLLOW(148, "left recursive rule '
- * lexer command 'command' does not exist or is not supported by
+ * lexer command command does not exist or is not supported by
* the current target Each lexer command requires an explicit implementation in the target
@@ -691,11 +703,11 @@ public enum ErrorType {
*
* @since 4.1
*/
- INVALID_LEXER_COMMAND(149, "lexer command ' missing argument for lexer command 'command' missing argument for lexer command command Some lexer commands require an argument. lexer command 'command' does not take any arguments lexer command command does not take any arguments A lexer command which does not take parameters was invoked with an
* argument.
- * rule 'rule' contains a closure with at least one alternative
+ * rule rule contains a closure with at least one alternative
* that can match an empty string A rule contains a closure ({@code (...)*}) or positive closure
@@ -765,12 +777,12 @@ public enum ErrorType {
*
* @since 4.1
*/
- EPSILON_CLOSURE(153, "rule '
- * rule 'rule' contains an optional block with at least one
+ * rule rule contains an optional block with at least one
* alternative that can match an empty string A rule contains an optional block ({@code (...)?}) around an empty
@@ -787,12 +799,12 @@ public enum ErrorType {
*
* @since 4.1
*/
- EPSILON_OPTIONAL(154, "rule '
- * rule 'rule' contains a lexer command with an unrecognized
+ * rule rule contains a lexer command with an unrecognized
* constant value; lexer interpreters may produce incorrect output A lexer rule contains a standard lexer command, but the constant value
@@ -814,7 +826,7 @@ public enum ErrorType {
*
* @since 4.2
*/
- UNKNOWN_LEXER_CONSTANT(155, "rule ' rule 'rule' contains an 'assoc' element option in an
+ * rule rule contains an assoc element option in an
* unrecognized location
@@ -851,17 +863,17 @@ public enum ErrorType {
* fragment rule 'rule' contains an action or command which can
+ * fragment rule rule contains an action or command which can
* never be executed A lexer rule which is marked with the {@code fragment} modifier
@@ -888,24 +900,24 @@ public enum ErrorType {
*
* @since 4.2.1
*/
- FRAGMENT_ACTION_IGNORED(158, "fragment rule ' cannot declare a rule with reserved name 'rule' cannot declare a rule with reserved name rule A rule was declared with a reserved name. The following rule produces this error.
- * '{@code tokens {A; B;}}' syntax is now '{@code tokens {A, B}}' in ANTLR
+ * {@code tokens {A; B;}} syntax is now {@code tokens {A, B}} in ANTLR
* 4
@@ -956,13 +968,13 @@ public enum ErrorType {
* NOTE: ANTLR 4 does not allow a trailing comma to appear following the
* last token declared in the {@code tokens{}} block.
* assignments in {@code tokens{}} are not supported in ANTLR 4; use lexical
- * rule 'TokenName : LiteralValue;' instead
* ANTLR 3 allowed literal tokens to be declared and assigned a value within
@@ -971,7 +983,7 @@ public enum ErrorType {
* value declared in the {@code tokens{}} block should be converted to
* standard lexer rules.
* x : 'x'; // ok
- * y : 'y; // error 152
+ * y : 'y'; // error 152
*
*
* @since 4.1
@@ -748,7 +760,7 @@ public enum ErrorType {
* Compiler Error 153.
*
*
* x : 'x'
* | x '+'<assoc=right> x // warning 157
- * |<assoc=right> x '*' x // ok
+ * |<assoc=right> x * x // ok
* ;
*
*
* @since 4.2.1
*/
- UNRECOGNIZED_ASSOC_OPTION(157, "rule '
- * EOF : ' ' // error 159 (EOF is a reserved name)
+ * EOF : ' ' // error 159 (EOF is a reserved name)
* ;
*
*
* @since 4.2.1
*/
- RESERVED_RULE_NAME(159, "cannot declare a rule with reserved name '