can match the empty string", ErrorSeverity.WARNING),
/**
* Compiler Error 147.
*
*
- * 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 '' must contain an alternative which is not left recursive", ErrorSeverity.ERROR),
+ NO_NON_LR_ALTS(147, "left recursive rule must contain an alternative which is not left recursive", ErrorSeverity.ERROR),
/**
* Compiler Error 148.
*
*
- * 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 '' contains a left recursive alternative which can be followed by the empty string", ErrorSeverity.ERROR),
+ EPSILON_LR_FOLLOW(148, "left recursive rule contains a left recursive alternative which can be followed by the empty string", ErrorSeverity.ERROR),
/**
* Compiler Error 149.
*
*
- * 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
@@ -685,34 +697,34 @@ public enum ErrorType {
*
The following rule produces this error.
*
*
- * X : 'foo' -> type(Foo); // ok
- * Y : 'foo' -> token(Foo); // error 149 (token is not a supported lexer command)
+ * X : foo -> type(Foo); // ok
+ * Y : foo -> token(Foo); // error 149 (token is not a supported lexer command)
*
*
* @since 4.1
*/
- INVALID_LEXER_COMMAND(149, "lexer command '' does not exist or is not supported by the current target", ErrorSeverity.ERROR),
+ INVALID_LEXER_COMMAND(149, "lexer command does not exist or is not supported by the current target", ErrorSeverity.ERROR),
/**
* Compiler Error 150.
*
- * missing argument for lexer command 'command'
+ * missing argument for lexer command command
*
* Some lexer commands require an argument.
*
* The following rule produces this error.
*
*
- * X : 'foo' -> type(Foo); // ok
- * Y : 'foo' -> type; // error 150 (the type command requires an argument)
+ * X : foo -> type(Foo); // ok
+ * Y : foo -> type; // error 150 (the type command requires an argument)
*
*
* @since 4.1
*/
- MISSING_LEXER_COMMAND_ARGUMENT(150, "missing argument for lexer command ''", ErrorSeverity.ERROR),
+ MISSING_LEXER_COMMAND_ARGUMENT(150, "missing argument for lexer command ", ErrorSeverity.ERROR),
/**
* Compiler Error 151.
*
- * 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.
@@ -720,13 +732,13 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * X : 'foo' -> popMode; // ok
- * Y : 'foo' -> popMode(A); // error 151 (the popMode command does not take an argument)
+ * X : foo -> popMode; // ok
+ * Y : foo -> popMode(A); // error 151 (the popMode command does not take an argument)
*
*
* @since 4.1
*/
- UNWANTED_LEXER_COMMAND_ARGUMENT(151, "lexer command '' does not take any arguments", ErrorSeverity.ERROR),
+ UNWANTED_LEXER_COMMAND_ARGUMENT(151, "lexer command does not take any arguments", ErrorSeverity.ERROR),
/**
* Compiler Error 152.
*
@@ -737,8 +749,8 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * x : 'x'; // ok
- * y : 'y; // error 152
+ * x : x; // ok
+ * y : y; // error 152
*
*
* @since 4.1
@@ -748,7 +760,7 @@ public enum ErrorType {
* Compiler Error 153.
*
*
- * 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
@@ -759,18 +771,18 @@ public enum ErrorType {
*
* x : ;
* y : x+; // error 153
- * z1 : ('foo' | 'bar'? 'bar2'?)*; // error 153
- * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')*; // ok
+ * z1 : (foo | bar? bar2?)*; // error 153
+ * z2 : (foo | bar bar2? | bar2)*; // ok
*
*
* @since 4.1
*/
- EPSILON_CLOSURE(153, "rule '' contains a closure with at least one alternative that can match an empty string", ErrorSeverity.ERROR),
+ EPSILON_CLOSURE(153, "rule contains a closure with at least one alternative that can match an empty string", ErrorSeverity.ERROR),
/**
* Compiler Warning 154.
*
*
- * 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
@@ -781,18 +793,18 @@ public enum ErrorType {
*
* x : ;
* y : x?; // warning 154
- * z1 : ('foo' | 'bar'? 'bar2'?)?; // warning 154
- * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')?; // ok
+ * z1 : (foo | bar? bar2?)?; // warning 154
+ * z2 : (foo | bar bar2? | bar2)?; // ok
*
*
* @since 4.1
*/
- EPSILON_OPTIONAL(154, "rule '' contains an optional block with at least one alternative that can match an empty string", ErrorSeverity.WARNING),
+ EPSILON_OPTIONAL(154, "rule contains an optional block with at least one alternative that can match an empty string", ErrorSeverity.WARNING),
/**
* Compiler Warning 155.
*
*
- * 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
@@ -808,13 +820,13 @@ public enum ErrorType {
* public static final int CUSTOM = HIDDEN + 1;
* }
*
- * X : 'foo' -> channel(HIDDEN); // ok
- * Y : 'bar' -> channel(CUSTOM); // warning 155
+ * X : foo -> channel(HIDDEN); // ok
+ * Y : bar -> channel(CUSTOM); // warning 155
*
*
* @since 4.2
*/
- UNKNOWN_LEXER_CONSTANT(155, "rule '' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output", ErrorSeverity.WARNING),
+ UNKNOWN_LEXER_CONSTANT(155, "rule contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output", ErrorSeverity.WARNING),
/**
* Compiler Error 156.
*
@@ -825,8 +837,8 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * x : 'x'; // ok
- * y : '\u005Cu'; // error 156
+ * x : x; // ok
+ * y : \u005Cu; // error 156
*
*
* @since 4.2.1
@@ -835,7 +847,7 @@ public enum ErrorType {
/**
* Compiler Warning 157.
*
- * rule 'rule' contains an 'assoc' element option in an
+ *
rule rule contains an assoc element option in an
* unrecognized location
*
*
@@ -849,19 +861,19 @@ public enum ErrorType {
*
The following rule produces this warning.
*
*
- * x : 'x'
- * | x '+'<assoc=right> x // warning 157
- * |<assoc=right> x '*' x // ok
+ * x : x
+ * | x +<assoc=right> x // warning 157
+ * |<assoc=right> x * x // ok
* ;
*
*
* @since 4.2.1
*/
- UNRECOGNIZED_ASSOC_OPTION(157, "rule '' contains an 'assoc' terminal option in an unrecognized location", ErrorSeverity.WARNING),
+ UNRECOGNIZED_ASSOC_OPTION(157, "rule contains an assoc terminal option in an unrecognized location", ErrorSeverity.WARNING),
/**
* Compiler Warning 158.
*
- * 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
@@ -874,38 +886,38 @@ public enum ErrorType {
*
The following rule produces this warning.
*
*
- * X1 : 'x' -> more // ok
+ * X1 : x -> more // ok
* ;
- * Y1 : 'x' {more();} // ok
+ * Y1 : x {more();} // ok
* ;
* fragment
- * X2 : 'x' -> more // warning 158
+ * X2 : x -> more // warning 158
* ;
* fragment
- * Y2 : 'x' {more();} // warning 158
+ * Y2 : x {more();} // warning 158
* ;
*
*
* @since 4.2.1
*/
- FRAGMENT_ACTION_IGNORED(158, "fragment rule '' contains an action or command which can never be executed", ErrorSeverity.WARNING),
+ FRAGMENT_ACTION_IGNORED(158, "fragment rule contains an action or command which can never be executed", ErrorSeverity.WARNING),
/**
* Compiler Error 159.
*
- * 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.
*
*
- * 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 ''", ErrorSeverity.ERROR),
+ RESERVED_RULE_NAME(159, "cannot declare a rule with reserved name ", ErrorSeverity.ERROR),
/*
* Backward incompatibility errors
@@ -944,7 +956,7 @@ public enum ErrorType {
* Compiler Warning 202.
*
*
- * '{@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.
*/
- V3_TOKENS_SYNTAX(202, "'tokens {A; B;}' syntax is now 'tokens {A, B}' in ANTLR 4", ErrorSeverity.WARNING),
+ V3_TOKENS_SYNTAX(202, "tokens {A; B;} syntax is now tokens {A, B} in ANTLR 4", ErrorSeverity.WARNING),
/**
* Compiler Error 203.
*
*
* assignments in {@code tokens{}} are not supported in ANTLR 4; use lexical
- * rule 'TokenName : LiteralValue;' instead
+ * 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.
*/
- V3_ASSIGN_IN_TOKENS(203, "assignments in tokens{} are not supported in ANTLR 4; use lexical rule ' : ;' instead", ErrorSeverity.ERROR),
+ V3_ASSIGN_IN_TOKENS(203, "assignments in tokens{} are not supported in ANTLR 4; use lexical rule : ; instead", ErrorSeverity.ERROR),
/**
* Compiler Warning 204.
*
@@ -993,7 +1005,7 @@ public enum ErrorType {
* {@code (...)=>} syntactic predicates are not supported in ANTLR 4
*
*
- * ANTLR 4's improved lookahead algorithms do not require the use of
+ * ANTLR 4s improved lookahead algorithms do not require the use of
* syntactic predicates to disambiguate long lookahead sequences. The
* syntactic predicates should be removed when migrating a grammar from
* ANTLR 3 to ANTLR 4.
diff --git a/tool/src/org/antlr/v4/tool/Grammar.java b/tool/src/org/antlr/v4/tool/Grammar.java
index fbdcbdf17..a716ebc72 100644
--- a/tool/src/org/antlr/v4/tool/Grammar.java
+++ b/tool/src/org/antlr/v4/tool/Grammar.java
@@ -30,6 +30,7 @@
package org.antlr.v4.tool;
+import org.antlr.runtime.tree.Tree;
import org.antlr.v4.Tool;
import org.antlr.v4.analysis.LeftRecursiveRuleTransformer;
import org.antlr.v4.misc.CharSupport;
@@ -355,7 +356,8 @@ public class Grammar implements AttributeResolver {
GrammarAST t = (GrammarAST)c;
String importedGrammarName = null;
if ( t.getType()==ANTLRParser.ASSIGN ) {
- importedGrammarName = t.getChild(1).getText();
+ t = (GrammarAST)t.getChild(1);
+ importedGrammarName = t.getText();
tool.log("grammar", "import "+ importedGrammarName);
}
else if ( t.getType()==ANTLRParser.ID ) {
@@ -364,11 +366,14 @@ public class Grammar implements AttributeResolver {
}
Grammar g;
try {
- g = tool.loadImportedGrammar(this, importedGrammarName);
+ g = tool.loadImportedGrammar(this, t);
}
catch (IOException ioe) {
- tool.errMgr.toolError(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, ioe,
- importedGrammarName);
+ tool.errMgr.grammarError(ErrorType.ERROR_READING_IMPORTED_GRAMMAR,
+ importedGrammarName,
+ t.getToken(),
+ importedGrammarName,
+ name);
continue;
}
// did it come back as error node or missing?
@@ -811,7 +816,7 @@ public class Grammar implements AttributeResolver {
public void importTokensFromTokensFile() {
String vocab = getOptionString("tokenVocab");
if ( vocab!=null ) {
- TokenVocabParser vparser = new TokenVocabParser(tool, vocab);
+ TokenVocabParser vparser = new TokenVocabParser(this);
Map tokens = vparser.load();
tool.log("grammar", "tokens=" + tokens);
for (String t : tokens.keySet()) {
diff --git a/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java b/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java
index 9f1475a96..72e750122 100644
--- a/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java
+++ b/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java
@@ -33,40 +33,17 @@ package org.antlr.v4.tool;
import org.antlr.runtime.Token;
/** A problem with the symbols and/or meaning of a grammar such as rule
- * redefinition.
+ * redefinition. Any msg where we can point to a location in the grammar.
*/
public class GrammarSemanticsMessage extends ANTLRMessage {
- public Grammar g;
- /** Most of the time, we'll have a token such as an undefined rule ref
- * and so this will be set.
- */
- public Token offendingToken;
-
- /*
- public GrammarSemanticsMessage(ErrorType etype,
- Grammar g,
- Token offendingToken,
- Object... args)
- {
- super(etype,args);
- this.g = g;
- if ( g!=null ) fileName = g.fileName;
- this.offendingToken = offendingToken;
- if ( offendingToken!=null ) {
- line = offendingToken.getLine();
- charPosition = offendingToken.getCharPositionInLine();
- }
- }
-*/
public GrammarSemanticsMessage(ErrorType etype,
String fileName,
Token offendingToken,
Object... args)
{
- super(etype,args);
+ super(etype,offendingToken,args);
this.fileName = fileName;
- this.offendingToken = offendingToken;
- if ( offendingToken!=null ) {
+ if ( offendingToken!=null ) {
line = offendingToken.getLine();
charPosition = offendingToken.getCharPositionInLine();
}
diff --git a/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java b/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java
index 8c4767c29..4648a84d1 100644
--- a/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java
+++ b/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java
@@ -37,17 +37,13 @@ import org.antlr.runtime.Token;
* "The '{' came as a complete surprise to me at this point in your program"
*/
public class GrammarSyntaxMessage extends ANTLRMessage {
- public Grammar g;
- /** Most of the time, we'll have a token and so this will be set. */
- public Token offendingToken;
-
public GrammarSyntaxMessage(ErrorType etype,
String fileName,
Token offendingToken,
RecognitionException antlrException,
Object... args)
{
- super(etype, antlrException, args);
+ super(etype, antlrException, offendingToken, args);
this.fileName = fileName;
this.offendingToken = offendingToken;
if ( offendingToken!=null ) {
diff --git a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java
index c04d6e515..5e352d3bf 100644
--- a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java
+++ b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java
@@ -30,14 +30,13 @@
package org.antlr.v4.tool;
+import org.antlr.runtime.Token;
+
import java.util.Collection;
public class LeftRecursionCyclesMessage extends ANTLRMessage {
- public Collection extends Collection> cycles;
-
- public LeftRecursionCyclesMessage(String fileName, Collection extends Collection> cycles) {
- super(ErrorType.LEFT_RECURSION_CYCLES, cycles);
- this.cycles = cycles;
+ public LeftRecursionCyclesMessage(String fileName, Token startTokenOfFirstRuleInCycle, Collection extends Collection> cycles) {
+ super(ErrorType.LEFT_RECURSION_CYCLES, startTokenOfFirstRuleInCycle, cycles);
this.fileName = fileName;
}
}
diff --git a/tool/src/org/antlr/v4/tool/ToolMessage.java b/tool/src/org/antlr/v4/tool/ToolMessage.java
index 3283d4bde..422eda232 100644
--- a/tool/src/org/antlr/v4/tool/ToolMessage.java
+++ b/tool/src/org/antlr/v4/tool/ToolMessage.java
@@ -30,6 +30,8 @@
package org.antlr.v4.tool;
+import org.antlr.runtime.Token;
+
/** A generic message from the tool such as "file not found" type errors; there
* is no reason to create a special object for each error unlike the grammar
* errors, which may be rather complex.
@@ -43,9 +45,9 @@ public class ToolMessage extends ANTLRMessage {
super(errorType);
}
public ToolMessage(ErrorType errorType, Object... args) {
- super(errorType, null, args);
+ super(errorType, null, Token.INVALID_TOKEN, args);
}
public ToolMessage(ErrorType errorType, Throwable e, Object... args) {
- super(errorType, e, args);
+ super(errorType, e, Token.INVALID_TOKEN, args);
}
}
diff --git a/tool/test/org/antlr/v4/test/TestAttributeChecks.java b/tool/test/org/antlr/v4/test/TestAttributeChecks.java
index a3b23700d..7cb8fed61 100644
--- a/tool/test/org/antlr/v4/test/TestAttributeChecks.java
+++ b/tool/test/org/antlr/v4/test/TestAttributeChecks.java
@@ -16,7 +16,7 @@
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
@@ -55,8 +55,8 @@ public class TestAttributeChecks extends BaseTest {
"c : ;\n";
String[] membersChecks = {
- "$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference 'a' in '$a'\n",
- "$a.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference 'a' in '$a.y'\n",
+ "$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a\n",
+ "$a.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a.y\n",
};
String[] initChecks = {
@@ -68,8 +68,8 @@ public class TestAttributeChecks extends BaseTest {
"$ids", "",
"$labs", "",
- "$c", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference 'c' in '$c'\n",
- "$a.q", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:10: unknown attribute 'q' for rule 'a' in '$a.q'\n",
+ "$c", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference c in $c\n",
+ "$a.q", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:10: unknown attribute q for rule a in $a.q\n",
};
String[] inlineChecks = {
@@ -92,21 +92,21 @@ public class TestAttributeChecks extends BaseTest {
};
String[] bad_inlineChecks = {
- "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'lab' in '$lab'\n",
- "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q'\n",
- "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q.y'\n",
- "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q'\n",
- "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q = 3;'\n",
- "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q.y'\n",
- "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q = $blort;'\n" +
- "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:9: unknown attribute reference 'blort' in '$blort'\n",
- "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
- "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
- "$b.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:6: parameter 'd' of rule 'b' is not accessible in this scope: $b.d\n", // can't see rule ref's arg
- "$d.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'd' in '$d.text'\n", // valid rule, but no ref
- "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:8: parameter 'd' of rule 'b' is not accessible in this scope: $lab.d\n",
- "$ids = null;", "error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label 'ids'\n",
- "$labs = null;","error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label 'labs'\n",
+ "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference lab in $lab\n",
+ "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q\n",
+ "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q.y\n",
+ "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q\n",
+ "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q = 3;\n",
+ "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q.y\n",
+ "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q = $blort;\n" +
+ "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:9: unknown attribute reference blort in $blort\n",
+ "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute ick for rule a in $a.ick\n",
+ "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute ick for rule a in $a.ick\n",
+ "$b.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:6: parameter d of rule b is not accessible in this scope: $b.d\n", // cant see rule refs arg
+ "$d.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference d in $d.text\n", // valid rule, but no ref
+ "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:8: parameter d of rule b is not accessible in this scope: $lab.d\n",
+ "$ids = null;", "error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label ids\n",
+ "$labs = null;","error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label labs\n",
};
String[] finallyChecks = {
@@ -121,97 +121,97 @@ public class TestAttributeChecks extends BaseTest {
"$ids", "",
"$labs", "",
- "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference 'lab' in '$lab'\n",
- "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q'\n",
- "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q.y'\n",
- "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q'\n",
- "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q = 3;'\n",
- "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q.y'\n",
- "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q = $blort;'\n" +
- "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:19: unknown attribute reference 'blort' in '$blort'\n",
- "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
- "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
- "$b.e", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b.e'\n", // can't see rule refs outside alts
- "$b.d", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b.d'\n",
- "$c.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'c' in '$c.text'\n",
- "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:10:18: parameter 'd' of rule 'b' is not accessible in this scope: $lab.d\n",
+ "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference lab in $lab\n",
+ "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q\n",
+ "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q.y\n",
+ "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q\n",
+ "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q = 3;\n",
+ "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q.y\n",
+ "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q = $blort;\n" +
+ "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:19: unknown attribute reference blort in $blort\n",
+ "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute ick for rule a in $a.ick\n",
+ "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute ick for rule a in $a.ick\n",
+ "$b.e", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference b in $b.e\n", // cant see rule refs outside alts
+ "$b.d", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference b in $b.d\n",
+ "$c.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference c in $c.text\n",
+ "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:10:18: parameter d of rule b is not accessible in this scope: $lab.d\n",
};
String[] dynMembersChecks = {
- "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference 'S' in '$S'\n",
- "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::i'\n",
- "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::i'\n" +
- "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:17: reference to undefined rule 'S' in non-local ref '$S::i'\n",
+ "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference S in $S\n",
+ "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::i\n",
+ "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::i\n" +
+ "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:17: reference to undefined rule S in non-local ref $S::i\n",
- "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:2:14: unknown attribute 'f' for rule 'b' in '$b::f'\n",
- "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::j'\n",
- "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n",
- "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n",
+ "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:2:14: unknown attribute f for rule b in $b::f\n",
+ "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::j\n",
+ "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::j = 3;\n",
+ "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::j = $S::k;\n",
};
String[] dynInitChecks = {
- "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference 'a' in '$a'\n",
- "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference 'b' in '$b'\n",
- "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference 'lab' in '$lab'\n",
- "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute 'f' for rule 'b' in '$b::f'\n",
- "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::i'\n",
- "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::i'\n" +
- "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:14: reference to undefined rule 'S' in non-local ref '$S::i'\n",
- "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute 'z' for rule 'a' in '$a::z'\n",
- "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference 'S' in '$S'\n",
+ "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference a in $a\n",
+ "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference b in $b\n",
+ "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference lab in $lab\n",
+ "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute f for rule b in $b::f\n",
+ "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::i\n",
+ "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::i\n" +
+ "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:14: reference to undefined rule S in non-local ref $S::i\n",
+ "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute z for rule a in $a::z\n",
+ "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference S in $S\n",
- "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::j'\n",
- "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n",
- "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n",
+ "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::j\n",
+ "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::j = 3;\n",
+ "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::j = $S::k;\n",
};
String[] dynInlineChecks = {
- "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'a' in '$a'\n",
- "$b", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'b' in '$b'\n",
- "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'lab' in '$lab'\n",
- "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute 'f' for rule 'b' in '$b::f'\n",
- "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::i'\n",
- "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::i'\n" +
- "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:10: reference to undefined rule 'S' in non-local ref '$S::i'\n",
- "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute 'z' for rule 'a' in '$a::z'\n",
+ "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference a in $a\n",
+ "$b", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference b in $b\n",
+ "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference lab in $lab\n",
+ "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute f for rule b in $b::f\n",
+ "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::i\n",
+ "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::i\n" +
+ "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:10: reference to undefined rule S in non-local ref $S::i\n",
+ "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute z for rule a in $a::z\n",
- "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::j'\n",
- "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n",
- "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n",
- "$Q[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$Q[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$Q[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$Q[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$Q[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$Q[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$Q[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$Q[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n",
- "$S[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n",
- "$S[$S::y]::i", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n" +
- "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:7: reference to undefined rule 'S' in non-local ref '$S::y'\n"
+ "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::j\n",
+ "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::j = 3;\n",
+ "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::j = $S::k;\n",
+ "$Q[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$Q[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$Q[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$Q[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$Q[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$Q[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$Q[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$Q[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n",
+ "$S[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n",
+ "$S[$S::y]::i", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n" +
+ "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:7: reference to undefined rule S in non-local ref $S::y\n"
};
String[] dynFinallyChecks = {
- "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference 'a' in '$a'\n",
- "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b'\n",
- "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference 'lab' in '$lab'\n",
- "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute 'f' for rule 'b' in '$b::f'\n",
- "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'S' in '$S'\n",
- "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::i'\n",
- "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::i'\n" +
- "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:20: reference to undefined rule 'S' in non-local ref '$S::i'\n",
- "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute 'z' for rule 'a' in '$a::z'\n",
+ "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference a in $a\n",
+ "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference b in $b\n",
+ "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference lab in $lab\n",
+ "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute f for rule b in $b::f\n",
+ "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference S in $S\n",
+ "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::i\n",
+ "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::i\n" +
+ "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:20: reference to undefined rule S in non-local ref $S::i\n",
+ "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute z for rule a in $a::z\n",
- "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::j'\n",
- "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n",
- "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n",
+ "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::j\n",
+ "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::j = 3;\n",
+ "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::j = $S::k;\n",
};
@Test public void testMembersActions() throws RecognitionException {
diff --git a/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java b/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java
index 697c47017..1b376f6a0 100644
--- a/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java
+++ b/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java
@@ -54,17 +54,17 @@ public class TestBasicSemanticErrors extends BaseTest {
"b : ( options { ick=bar; greedy=true; } : ID )+ ;\n" +
"c : ID ID ;",
// YIELDS
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:10: unsupported option 'foo'\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:19: unsupported option 'k'\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:10: unsupported option foo\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:19: unsupported option k\n" +
"error(" + ErrorType.TOKEN_NAMES_MUST_START_UPPER.code + "): U.g4:5:8: token names must start with an uppercase letter: f\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:9:10: unsupported option 'x'\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:9:10: unsupported option x\n" +
"error(" + ErrorType.REPEATED_PREQUEL.code + "): U.g4:9:0: repeated grammar prequel spec (options, tokens, or import); please merge\n" +
"error(" + ErrorType.REPEATED_PREQUEL.code + "): U.g4:8:0: repeated grammar prequel spec (options, tokens, or import); please merge\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:10: unsupported option 'blech'\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:21: unsupported option 'greedy'\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:16: unsupported option 'ick'\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:25: unsupported option 'greedy'\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:16:16: unsupported option 'x'\n",
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:10: unsupported option blech\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:21: unsupported option greedy\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:16: unsupported option ick\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:25: unsupported option greedy\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:16:16: unsupported option x\n",
};
@Test public void testU() { super.testErrors(U, false); }
@@ -82,7 +82,7 @@ public class TestBasicSemanticErrors extends BaseTest {
"";
String expected =
- "error(" + ErrorType.LABEL_BLOCK_NOT_A_SET.code + "): T.g4:2:5: label 'op' assigned to a block which is not a set\n";
+ "error(" + ErrorType.LABEL_BLOCK_NOT_A_SET.code + "): T.g4:2:5: label op assigned to a block which is not a set\n";
testErrors(new String[] { grammar, expected }, false);
}
@@ -97,16 +97,16 @@ public class TestBasicSemanticErrors extends BaseTest {
"expr : '=';\n";
String expected =
- "error(" + ErrorType.ARG_CONFLICTS_WITH_RULE.code + "): T.g4:2:7: parameter 'expr' conflicts with rule with same name\n" +
- "error(" + ErrorType.RETVAL_CONFLICTS_WITH_RULE.code + "): T.g4:2:26: return value 'expr' conflicts with rule with same name\n" +
- "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RULE.code + "): T.g4:3:12: local 'expr' conflicts with rule with same name\n" +
- "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): T.g4:2:26: return value 'expr' conflicts with parameter with same name\n" +
- "error(" + ErrorType.LOCAL_CONFLICTS_WITH_ARG.code + "): T.g4:3:12: local 'expr' conflicts with parameter with same name\n" +
- "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RETVAL.code + "): T.g4:3:12: local 'expr' conflicts with return value with same name\n" +
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): T.g4:4:4: label 'expr' conflicts with rule with same name\n" +
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): T.g4:4:4: label 'expr' conflicts with parameter with same name\n" +
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_RETVAL.code + "): T.g4:4:4: label 'expr' conflicts with return value with same name\n" +
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_LOCAL.code + "): T.g4:4:4: label 'expr' conflicts with local with same name\n";
+ "error(" + ErrorType.ARG_CONFLICTS_WITH_RULE.code + "): T.g4:2:7: parameter expr conflicts with rule with same name\n" +
+ "error(" + ErrorType.RETVAL_CONFLICTS_WITH_RULE.code + "): T.g4:2:26: return value expr conflicts with rule with same name\n" +
+ "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RULE.code + "): T.g4:3:12: local expr conflicts with rule with same name\n" +
+ "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): T.g4:2:26: return value expr conflicts with parameter with same name\n" +
+ "error(" + ErrorType.LOCAL_CONFLICTS_WITH_ARG.code + "): T.g4:3:12: local expr conflicts with parameter with same name\n" +
+ "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RETVAL.code + "): T.g4:3:12: local expr conflicts with return value with same name\n" +
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): T.g4:4:4: label expr conflicts with rule with same name\n" +
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): T.g4:4:4: label expr conflicts with parameter with same name\n" +
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_RETVAL.code + "): T.g4:4:4: label expr conflicts with return value with same name\n" +
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_LOCAL.code + "): T.g4:4:4: label expr conflicts with local with same name\n";
ST grammarST = new ST(grammarTemplate);
grammarST.add("args", "int expr");
grammarST.add("retvals", "int expr");
diff --git a/tool/test/org/antlr/v4/test/TestLeftRecursion.java b/tool/test/org/antlr/v4/test/TestLeftRecursion.java
index dbf161cba..9a3ed59c2 100644
--- a/tool/test/org/antlr/v4/test/TestLeftRecursion.java
+++ b/tool/test/org/antlr/v4/test/TestLeftRecursion.java
@@ -491,7 +491,7 @@ public class TestLeftRecursion extends BaseTest {
"ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') -> skip ;\n";
String expected =
- "error(" + ErrorType.NO_NON_LR_ALTS.code + "): T.g4:3:0: left recursive rule 'a' must contain an alternative which is not left recursive\n";
+ "error(" + ErrorType.NO_NON_LR_ALTS.code + "): T.g4:3:0: left recursive rule a must contain an alternative which is not left recursive\n";
testErrors(new String[] { grammar, expected }, false);
}
@@ -505,7 +505,7 @@ public class TestLeftRecursion extends BaseTest {
"ID : 'a'..'z'+ ;\n" +
"WS : (' '|'\\n') -> skip ;\n";
String expected =
- "error(" + ErrorType.EPSILON_LR_FOLLOW.code + "): T.g4:3:0: left recursive rule 'a' contains a left recursive alternative which can be followed by the empty string\n";
+ "error(" + ErrorType.EPSILON_LR_FOLLOW.code + "): T.g4:3:0: left recursive rule a contains a left recursive alternative which can be followed by the empty string\n";
testErrors(new String[] { grammar, expected }, false);
}
diff --git a/tool/test/org/antlr/v4/test/TestScopeParsing.java b/tool/test/org/antlr/v4/test/TestScopeParsing.java
index 98fe29a75..851bd4817 100644
--- a/tool/test/org/antlr/v4/test/TestScopeParsing.java
+++ b/tool/test/org/antlr/v4/test/TestScopeParsing.java
@@ -32,6 +32,7 @@ package org.antlr.v4.test;
import org.antlr.v4.parse.ScopeParser;
import org.antlr.v4.tool.ErrorManager;
+import org.antlr.v4.tool.Grammar;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -55,11 +56,12 @@ public class TestScopeParsing extends BaseTest {
"i,j, k", "{i=null i, j=null j, k=null k}",
};
- @Test public void testArgs() {
+ @Test public void testArgs() throws Exception {
for (int i = 0; i < argPairs.length; i+=2) {
String input = argPairs[i];
String expected = argPairs[i+1];
- String actual = ScopeParser.parseTypedArgList(null, input, new ErrorManager(null)).attributes.toString();
+ Grammar dummy = new Grammar("grammar T; a:'a';");
+ String actual = ScopeParser.parseTypedArgList(null, input, dummy).attributes.toString();
assertEquals(expected, actual);
}
}
diff --git a/tool/test/org/antlr/v4/test/TestSets.java b/tool/test/org/antlr/v4/test/TestSets.java
index da9ef1c28..12f5a00d8 100644
--- a/tool/test/org/antlr/v4/test/TestSets.java
+++ b/tool/test/org/antlr/v4/test/TestSets.java
@@ -238,7 +238,7 @@ public class TestSets extends BaseTest {
"a : A {System.out.println($A.text);} ;\n" +
"A : ~('a'|B) ;\n" +
"B : 'b' ;\n",
- "error(" + ErrorType.UNSUPPORTED_REFERENCE_IN_LEXER_SET.code + "): T.g4:3:10: rule reference 'B' is not currently supported in a set\n"
+ "error(" + ErrorType.UNSUPPORTED_REFERENCE_IN_LEXER_SET.code + "): T.g4:3:10: rule reference B is not currently supported in a set\n"
};
super.testErrors(pair, true);
}
diff --git a/tool/test/org/antlr/v4/test/TestSymbolIssues.java b/tool/test/org/antlr/v4/test/TestSymbolIssues.java
index f863687ab..7d6d8f92c 100644
--- a/tool/test/org/antlr/v4/test/TestSymbolIssues.java
+++ b/tool/test/org/antlr/v4/test/TestSymbolIssues.java
@@ -54,15 +54,15 @@ public class TestSymbolIssues extends BaseTest {
"\n" +
"ID : 'a'..'z'+ ID ;",
// YIELDS
- "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of 'members' action\n" +
- "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:7:1: redefinition of 'header' action\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:10: unsupported option 'opt'\n" +
- "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:21: unsupported option 'k'\n" +
- "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of 'members' action\n" +
- "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:9:27: implicit definition of token 'X' in parser\n" +
- "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:10:20: implicit definition of token 'Y' in parser\n" +
- "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:11:4: implicit definition of token 'FJKD' in parser\n" +
- "error(" + ErrorType.RULE_HAS_NO_ARGS.code + "): A.g4:9:37: rule 'b' has no defined parameters\n" +
+ "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of members action\n" +
+ "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:7:1: redefinition of header action\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:10: unsupported option opt\n" +
+ "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:21: unsupported option k\n" +
+ "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of members action\n" +
+ "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:9:27: implicit definition of token X in parser\n" +
+ "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:10:20: implicit definition of token Y in parser\n" +
+ "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:11:4: implicit definition of token FJKD in parser\n" +
+ "error(" + ErrorType.RULE_HAS_NO_ARGS.code + "): A.g4:9:37: rule b has no defined parameters\n" +
"error(" + ErrorType.MISSING_RULE_ARGS.code + "): A.g4:10:31: missing arguments(s) on rule reference: a\n"
};
@@ -77,10 +77,10 @@ public class TestSymbolIssues extends BaseTest {
"\n" +
"s : FOO ;",
// YIELDS
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:4: label 's' conflicts with rule with same name\n" +
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:9: label 'b' conflicts with rule with same name\n" +
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_TOKEN.code + "): B.g4:4:15: label 'X' conflicts with token with same name\n" +
- "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): B.g4:6:9: label 'x' type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n" +
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:4: label s conflicts with rule with same name\n" +
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:9: label b conflicts with rule with same name\n" +
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_TOKEN.code + "): B.g4:4:15: label X conflicts with token with same name\n" +
+ "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): B.g4:6:9: label x type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n" +
"error(" + ErrorType.IMPLICIT_STRING_DEFINITION.code + "): B.g4:4:20: cannot create implicit token for string literal in non-combined grammar: '.'\n"
};
@@ -97,8 +97,8 @@ public class TestSymbolIssues extends BaseTest {
" : ID ;",
// YIELDS
- "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): D.g4:4:21: label 'j' conflicts with parameter with same name\n" +
- "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): D.g4:6:22: return value 'i' conflicts with parameter with same name\n"
+ "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): D.g4:4:21: label j conflicts with parameter with same name\n" +
+ "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): D.g4:6:22: return value i conflicts with parameter with same name\n"
};
static String[] E = {
@@ -112,7 +112,7 @@ public class TestSymbolIssues extends BaseTest {
"a : A ;\n",
// YIELDS
- "warning(" + ErrorType.TOKEN_NAME_REASSIGNMENT.code + "): E.g4:3:4: token name 'A' is already defined\n"
+ "warning(" + ErrorType.TOKEN_NAME_REASSIGNMENT.code + "): E.g4:3:4: token name A is already defined\n"
};
@Test public void testA() { super.testErrors(A, false); }
@@ -147,7 +147,7 @@ public class TestSymbolIssues extends BaseTest {
"mode X;\n" +
"fragment B : 'b';",
- "error(" + ErrorType.MODE_WITHOUT_RULES.code + "): L.g4:3:5: lexer mode 'X' must contain at least one non-fragment rule\n"
+ "error(" + ErrorType.MODE_WITHOUT_RULES.code + "): L.g4:3:5: lexer mode X must contain at least one non-fragment rule\n"
};
testErrors(test, false);
@@ -162,8 +162,8 @@ public class TestSymbolIssues extends BaseTest {
" B : C;\n" +
" fragment C : A | (A C)?;",
- "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:3:0: non-fragment lexer rule 'WS' can match the empty string\n" +
- "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:5:2: non-fragment lexer rule 'B' can match the empty string\n"
+ "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:3:0: non-fragment lexer rule WS can match the empty string\n" +
+ "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:5:2: non-fragment lexer rule B can match the empty string\n"
};
testErrors(test, false);
diff --git a/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java b/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java
index 995b9d3e6..1b79140fa 100644
--- a/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java
+++ b/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java
@@ -39,7 +39,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"grammar A;\n" +
"",
// YIELDS
- "error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar 'A' has no rules\n",
+ "error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n",
"A;",
"error(" + ErrorType.SYNTAX_ERROR.code + "): A.g4:1:0: syntax error: 'A' came as a complete surprise to me\n",
@@ -273,8 +273,8 @@ public class TestToolSyntaxErrors extends BaseTest {
"X : 'foo' -> popmode;\n" + // "meant" to use -> popMode
"Y : 'foo' -> token(Foo);", // "meant" to use -> type(Foo)
- "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:4:13: lexer command 'popmode' does not exist or is not supported by the current target\n" +
- "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:5:13: lexer command 'token' does not exist or is not supported by the current target\n"
+ "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:4:13: lexer command popmode does not exist or is not supported by the current target\n" +
+ "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:5:13: lexer command token does not exist or is not supported by the current target\n"
};
super.testErrors(pair, true);
}
@@ -287,8 +287,8 @@ public class TestToolSyntaxErrors extends BaseTest {
"X : 'foo' -> popMode(Foo);\n" + // "meant" to use -> popMode
"Y : 'foo' -> type;", // "meant" to use -> type(Foo)
- "error(" + ErrorType.UNWANTED_LEXER_COMMAND_ARGUMENT.code + "): A.g4:4:13: lexer command 'popMode' does not take any arguments\n" +
- "error(" + ErrorType.MISSING_LEXER_COMMAND_ARGUMENT.code + "): A.g4:5:13: missing argument for lexer command 'type'\n"
+ "error(" + ErrorType.UNWANTED_LEXER_COMMAND_ARGUMENT.code + "): A.g4:4:13: lexer command popMode does not take any arguments\n" +
+ "error(" + ErrorType.MISSING_LEXER_COMMAND_ARGUMENT.code + "): A.g4:5:13: missing argument for lexer command type\n"
};
super.testErrors(pair, true);
}
@@ -303,7 +303,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"A : 'a' ;\n" +
"B : 'b' ;\n",
- "error(" + ErrorType.RULE_REDEFINITION.code + "): Oops.g4:4:0: rule 'ret_ty' redefinition; previous at line 3\n"
+ "error(" + ErrorType.RULE_REDEFINITION.code + "): Oops.g4:4:0: rule ret_ty redefinition; previous at line 3\n"
};
super.testErrors(pair, true);
}
@@ -317,15 +317,15 @@ public class TestToolSyntaxErrors extends BaseTest {
+ "z1 : ('foo' | 'bar'? 'bar2'?)*;\n"
+ "z2 : ('foo' | 'bar' 'bar2'? | 'bar2')*;\n";
String expected =
- "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:3:0: rule 'y1' contains a closure with at least one alternative that can match an empty string\n" +
- "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:4:0: rule 'y2' contains a closure with at least one alternative that can match an empty string\n" +
- "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:5:0: rule 'z1' contains a closure with at least one alternative that can match an empty string\n";
+ "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:3:0: rule y1 contains a closure with at least one alternative that can match an empty string\n" +
+ "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:4:0: rule y2 contains a closure with at least one alternative that can match an empty string\n" +
+ "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:5:0: rule z1 contains a closure with at least one alternative that can match an empty string\n";
String[] pair = new String[] {
grammar,
expected
};
-
+
super.testErrors(pair, true);
}
@@ -337,8 +337,8 @@ public class TestToolSyntaxErrors extends BaseTest {
+ "z1 : ('foo' | 'bar'? 'bar2'?)?;\n"
+ "z2 : ('foo' | 'bar' 'bar2'? | 'bar2')?;\n";
String expected =
- "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:3:0: rule 'y' contains an optional block with at least one alternative that can match an empty string\n" +
- "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:4:0: rule 'z1' contains an optional block with at least one alternative that can match an empty string\n";
+ "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:3:0: rule y contains an optional block with at least one alternative that can match an empty string\n" +
+ "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:4:0: rule z1 contains an optional block with at least one alternative that can match an empty string\n";
String[] pair = new String[] {
grammar,
@@ -373,7 +373,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"WS : [ \\r\\t\\n]+ -> skip ;\n";
String expected =
"";
-
+
String[] pair = new String[] { grammar, expected };
super.testErrors(pair, true);
}
@@ -464,7 +464,7 @@ public class TestToolSyntaxErrors extends BaseTest {
" | x '*' x // ok\n" +
" ;\n";
String expected =
- "warning(" + ErrorType.UNRECOGNIZED_ASSOC_OPTION.code + "): A.g4:3:10: rule 'x' contains an 'assoc' terminal option in an unrecognized location\n";
+ "warning(" + ErrorType.UNRECOGNIZED_ASSOC_OPTION.code + "): A.g4:3:10: rule x contains an assoc terminal option in an unrecognized location\n";
String[] pair = new String[] {
grammar,
@@ -492,8 +492,8 @@ public class TestToolSyntaxErrors extends BaseTest {
"Y2 : 'x' {more();} // warning 158\n" +
" ;\n";
String expected =
- "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:7:12: fragment rule 'X2' contains an action or command which can never be executed\n" +
- "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:10:9: fragment rule 'Y2' contains an action or command which can never be executed\n";
+ "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:7:12: fragment rule X2 contains an action or command which can never be executed\n" +
+ "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:10:9: fragment rule Y2 contains an action or command which can never be executed\n";
String[] pair = new String[] {
grammar,
@@ -514,7 +514,7 @@ public class TestToolSyntaxErrors extends BaseTest {
"WS : ' ';\n" +
" EOF : 'a';\n";
String expected =
- "error(" + ErrorType.RESERVED_RULE_NAME.code + "): A.g4:3:1: cannot declare a rule with reserved name 'EOF'\n";
+ "error(" + ErrorType.RESERVED_RULE_NAME.code + "): A.g4:3:1: cannot declare a rule with reserved name EOF\n";
String[] pair = new String[] {
grammar,
From f0ab9b1415d6e20cf634b6fe62b457733c01443d Mon Sep 17 00:00:00 2001
From: Terence Parr
Date: Mon, 30 Jun 2014 09:26:02 -0700
Subject: [PATCH 2/3] use assoc value's token.
---
tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java
index 09100ed5d..19b3f9a79 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.getToken(), "assoc", assoc);
+ tool.errMgr.toolError(ErrorType.ILLEGAL_OPTION_VALUE, t.getOptionAST("assoc").getToken(), "assoc", assoc);
}
}
}
From e3fc04bda1ce8bafaa55a2a584f26f2238c910c8 Mon Sep 17 00:00:00 2001
From: Terence Parr
Date: Mon, 30 Jun 2014 15:16:20 -0700
Subject: [PATCH 3/3] put good quotes back in. rm unneeded arg to left-recur
msg.
---
.../v4/analysis/LeftRecursionDetector.java | 4 +-
tool/src/org/antlr/v4/tool/ErrorManager.java | 4 +-
tool/src/org/antlr/v4/tool/ErrorType.java | 52 +++++++++----------
.../v4/tool/LeftRecursionCyclesMessage.java | 23 +++++++-
4 files changed, 50 insertions(+), 33 deletions(-)
diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java b/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java
index 61e0309a7..44e4b4a85 100644
--- a/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java
+++ b/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java
@@ -74,9 +74,7 @@ public class LeftRecursionDetector {
}
//System.out.println("cycles="+listOfRecursiveCycles);
if ( !listOfRecursiveCycles.isEmpty() ) {
- RuleStartState firstRuleStartState = atn.ruleToStartState[0];
- Rule r = g.getRule(firstRuleStartState.ruleIndex);
- g.tool.errMgr.leftRecursionCycles(g.fileName, r.ast.getToken(), listOfRecursiveCycles);
+ g.tool.errMgr.leftRecursionCycles(g.fileName, listOfRecursiveCycles);
}
}
diff --git a/tool/src/org/antlr/v4/tool/ErrorManager.java b/tool/src/org/antlr/v4/tool/ErrorManager.java
index 364316e21..fc196af20 100644
--- a/tool/src/org/antlr/v4/tool/ErrorManager.java
+++ b/tool/src/org/antlr/v4/tool/ErrorManager.java
@@ -186,9 +186,9 @@ public class ErrorManager {
}
- public void leftRecursionCycles(String fileName, Token startTokenOfFirstRuleInCycle, Collection extends Collection> cycles) {
+ public void leftRecursionCycles(String fileName, Collection extends Collection> cycles) {
errors++;
- ANTLRMessage msg = new LeftRecursionCyclesMessage(fileName, startTokenOfFirstRuleInCycle, cycles);
+ ANTLRMessage msg = new LeftRecursionCyclesMessage(fileName, cycles);
tool.error(msg);
}
diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java
index 56b4a12f5..4eb8dc2f6 100644
--- a/tool/src/org/antlr/v4/tool/ErrorType.java
+++ b/tool/src/org/antlr/v4/tool/ErrorType.java
@@ -16,7 +16,7 @@
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
@@ -178,7 +178,7 @@ public enum ErrorType {
/**
* Compiler Error 35.
*
- * templates/target and tool arent compatible
+ * templates/target and tool aren't compatible
*/
INCOMPATIBLE_TOOL_AND_TEMPLATES(35, " code generation target requires ANTLR ; it can't be loaded by the current ANTLR ", ErrorSeverity.ERROR),
@@ -697,8 +697,8 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * X : foo -> type(Foo); // ok
- * Y : foo -> token(Foo); // error 149 (token is not a supported lexer command)
+ * X : 'foo' -> type(Foo); // ok
+ * Y : 'foo' -> token(Foo); // error 149 (token is not a supported lexer command)
*
*
* @since 4.1
@@ -714,8 +714,8 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * X : foo -> type(Foo); // ok
- * Y : foo -> type; // error 150 (the type command requires an argument)
+ * X : 'foo' -> type(Foo); // ok
+ * Y : 'foo' -> type; // error 150 (the type command requires an argument)
*
*
* @since 4.1
@@ -732,8 +732,8 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * X : foo -> popMode; // ok
- * Y : foo -> popMode(A); // error 151 (the popMode command does not take an argument)
+ * X : 'foo' -> popMode; // ok
+ * Y : 'foo' -> popMode(A); // error 151 (the popMode command does not take an argument)
*
*
* @since 4.1
@@ -749,8 +749,8 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * x : x; // ok
- * y : y; // error 152
+ * x : 'x'; // ok
+ * y : 'y'; // error 152
*
*
* @since 4.1
@@ -771,8 +771,8 @@ public enum ErrorType {
*
* x : ;
* y : x+; // error 153
- * z1 : (foo | bar? bar2?)*; // error 153
- * z2 : (foo | bar bar2? | bar2)*; // ok
+ * z1 : ('foo' | 'bar'? 'bar2'?)*; // error 153
+ * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')*; // ok
*
*
* @since 4.1
@@ -793,8 +793,8 @@ public enum ErrorType {
*
* x : ;
* y : x?; // warning 154
- * z1 : (foo | bar? bar2?)?; // warning 154
- * z2 : (foo | bar bar2? | bar2)?; // ok
+ * z1 : ('foo' | 'bar'? 'bar2'?)?; // warning 154
+ * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')?; // ok
*
*
* @since 4.1
@@ -820,8 +820,8 @@ public enum ErrorType {
* public static final int CUSTOM = HIDDEN + 1;
* }
*
- * X : foo -> channel(HIDDEN); // ok
- * Y : bar -> channel(CUSTOM); // warning 155
+ * X : 'foo' -> channel(HIDDEN); // ok
+ * Y : 'bar' -> channel(CUSTOM); // warning 155
*
*
* @since 4.2
@@ -837,8 +837,8 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * x : x; // ok
- * y : \u005Cu; // error 156
+ * x : 'x'; // ok
+ * y : '\u005Cu'; // error 156
*
*
* @since 4.2.1
@@ -861,8 +861,8 @@ public enum ErrorType {
* The following rule produces this warning.
*
*
- * x : x
- * | x +<assoc=right> x // warning 157
+ * x : 'x'
+ * | x '+'<assoc=right> x // warning 157
* |<assoc=right> x * x // ok
* ;
*
@@ -886,15 +886,15 @@ public enum ErrorType {
* The following rule produces this warning.
*
*
- * X1 : x -> more // ok
+ * X1 : 'x' -> more // ok
* ;
- * Y1 : x {more();} // ok
+ * Y1 : 'x' {more();} // ok
* ;
* fragment
- * X2 : x -> more // warning 158
+ * X2 : 'x' -> more // warning 158
* ;
* fragment
- * Y2 : x {more();} // warning 158
+ * Y2 : 'x' {more();} // warning 158
* ;
*
*
@@ -911,7 +911,7 @@ public enum ErrorType {
* The following rule produces this error.
*
*
- * EOF : // error 159 (EOF is a reserved name)
+ * EOF : ' ' // error 159 (EOF is a reserved name)
* ;
*
*
@@ -1005,7 +1005,7 @@ public enum ErrorType {
* {@code (...)=>} syntactic predicates are not supported in ANTLR 4
*
*
- * ANTLR 4s improved lookahead algorithms do not require the use of
+ * ANTLR 4's improved lookahead algorithms do not require the use of
* syntactic predicates to disambiguate long lookahead sequences. The
* syntactic predicates should be removed when migrating a grammar from
* ANTLR 3 to ANTLR 4.
diff --git a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java
index 5e352d3bf..3e0740b2a 100644
--- a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java
+++ b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java
@@ -35,8 +35,27 @@ import org.antlr.runtime.Token;
import java.util.Collection;
public class LeftRecursionCyclesMessage extends ANTLRMessage {
- public LeftRecursionCyclesMessage(String fileName, Token startTokenOfFirstRuleInCycle, Collection extends Collection> cycles) {
- super(ErrorType.LEFT_RECURSION_CYCLES, startTokenOfFirstRuleInCycle, cycles);
+ public LeftRecursionCyclesMessage(String fileName, Collection extends Collection> cycles) {
+ super(ErrorType.LEFT_RECURSION_CYCLES, getStartTokenOfFirstRule(cycles), cycles);
this.fileName = fileName;
}
+
+ protected static Token getStartTokenOfFirstRule(Collection extends Collection> cycles) {
+ if (cycles == null) {
+ return null;
+ }
+
+ for (Collection collection : cycles) {
+ if (collection == null) {
+ return null;
+ }
+
+ for (Rule rule : collection) {
+ if (rule.ast != null) {
+ return rule.ast.getToken();
+ }
+ }
+ }
+ return null;
+ }
}