diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java index 710da08b4..1c68ba30a 100644 --- a/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java +++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java @@ -198,9 +198,9 @@ public class TestSymbolIssues extends BaseTest { "C: 'c';", "error(" + ErrorType.RESERVED_RULE_NAME.code + "): L.g4:5:0: cannot declare a rule with reserved name MIN_CHAR_VALUE\n" + - "error(" + ErrorType.MODE_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:4:0: can not use or declare mode with reserved name MAX_CHAR_VALUE\n" + - "error(" + ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:11: can not use or declare channel with reserved name SKIP\n" + - "error(" + ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:17: can not use or declare channel with reserved name HIDDEN\n" + "error(" + ErrorType.MODE_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:4:0: cannot use or declare mode with reserved name MAX_CHAR_VALUE\n" + + "error(" + ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:11: cannot use or declare channel with reserved name SKIP\n" + + "error(" + ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:17: cannot use or declare channel with reserved name HIDDEN\n" }; testErrors(test, false); @@ -216,9 +216,9 @@ public class TestSymbolIssues extends BaseTest { "E: 'e' -> type(EOF);\n" + "F: 'f' -> pushMode(DEFAULT_MODE);", - "error(" + ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:18: can not use or declare channel with reserved name SKIP\n" + - "error(" + ErrorType.TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:3:15: can not use or declare token with reserved name MORE\n" + - "error(" + ErrorType.MODE_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:4:15: can not use or declare mode with reserved name SKIP\n" + "error(" + ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:18: cannot use or declare channel with reserved name SKIP\n" + + "error(" + ErrorType.TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:3:15: cannot use or declare token with reserved name MORE\n" + + "error(" + ErrorType.MODE_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:4:15: cannot use or declare mode with reserved name SKIP\n" }; testErrors(test, false); diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java index f27baa87e..c41143422 100644 --- a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java +++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java @@ -467,11 +467,11 @@ public class TestToolSyntaxErrors extends BaseTest { "Error3: '';\n" + "NotError: ' ';"; String expected = - "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:2:8: empty strings not allowed\n" + - "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:2:16: empty strings not allowed\n" + - "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:3:8: empty strings not allowed\n" + - "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:4:15: empty strings not allowed\n" + - "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:5:8: empty strings not allowed\n"; + "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:2:8: string literals cannot be empty\n" + + "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:2:16: string literals cannot be empty\n" + + "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:3:8: string literals cannot be empty\n" + + "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:4:15: string literals cannot be empty\n" + + "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:5:8: string literals cannot be empty\n"; String[] pair = new String[] { grammar, diff --git a/tool/src/org/antlr/v4/automata/LexerATNFactory.java b/tool/src/org/antlr/v4/automata/LexerATNFactory.java index a1dcaf669..a5e80e47d 100644 --- a/tool/src/org/antlr/v4/automata/LexerATNFactory.java +++ b/tool/src/org/antlr/v4/automata/LexerATNFactory.java @@ -83,7 +83,7 @@ public class LexerATNFactory extends ParserATNFactory { * actions, but are required during code generation for creating * {@link LexerAction} instances that are usable by a lexer interpreter. */ - protected static final Map COMMON_CONSTANTS = new HashMap(); + public static final Map COMMON_CONSTANTS = new HashMap(); static { COMMON_CONSTANTS.put("HIDDEN", Lexer.HIDDEN); COMMON_CONSTANTS.put("DEFAULT_TOKEN_CHANNEL", Lexer.DEFAULT_TOKEN_CHANNEL); diff --git a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java index 73fd95ed1..ada4324ba 100644 --- a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java +++ b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java @@ -69,11 +69,6 @@ import java.util.Set; * tokens and rules from the imported grammars into a single collection. */ public class SemanticPipeline { - protected final Set reservedNames = new HashSet(); - { - reservedNames.addAll(LexerATNFactory.getCommonConstants()); - } - public Grammar g; public SemanticPipeline(Grammar g) { @@ -295,7 +290,7 @@ public class SemanticPipeline { g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_TOKEN, g.fileName, channel.token, channelName); } - if (reservedNames.contains(channelName)) { + if (LexerATNFactory.COMMON_CONSTANTS.containsKey(channelName)) { g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, channel.token, channelName); } diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index c733e07c8..0fedfc4a9 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -978,9 +978,9 @@ public enum ErrorType { * *

Reserved names: HIDDEN, DEFAULT_TOKEN_CHANNEL, SKIP, MORE, MAX_CHAR_VALUE, MIN_CHAR_VALUE. * - *

Can be used but can not be declared: EOF

+ *

Can be used but cannot be declared: EOF

*/ - TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS(171, "can not use or declare token with reserved name ", ErrorSeverity.ERROR), + TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS(171, "cannot use or declare token with reserved name ", ErrorSeverity.ERROR), /** * Compiler Error 172. * @@ -988,9 +988,9 @@ public enum ErrorType { * *

Reserved names: DEFAULT_MODE, SKIP, MORE, EOF, MAX_CHAR_VALUE, MIN_CHAR_VALUE. * - *

Can be used but can not be declared: HIDDEN, DEFAULT_TOKEN_CHANNEL

+ *

Can be used but cannot be declared: HIDDEN, DEFAULT_TOKEN_CHANNEL

*/ - CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS(172, "can not use or declare channel with reserved name ", ErrorSeverity.ERROR), + CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS(172, "cannot use or declare channel with reserved name ", ErrorSeverity.ERROR), /** * Compiler Error 173. * @@ -998,9 +998,9 @@ public enum ErrorType { * *

Reserved names: HIDDEN, DEFAULT_TOKEN_CHANNEL, SKIP, MORE, MAX_CHAR_VALUE, MIN_CHAR_VALUE. * - *

Can be used and can be declared: DEFAULT_MODE

+ *

Can be used and cannot declared: DEFAULT_MODE

*/ - MODE_CONFLICTS_WITH_COMMON_CONSTANTS(173, "can not use or declare mode with reserved name ", ErrorSeverity.ERROR), + MODE_CONFLICTS_WITH_COMMON_CONSTANTS(173, "cannot use or declare mode with reserved name ", ErrorSeverity.ERROR), /** * Compiler Error 174. * @@ -1010,7 +1010,7 @@ public enum ErrorType { *
B: '';
*
C: 'test' '';
*/ - EMPTY_STRINGS_NOT_ALLOWED(174, "empty strings not allowed", ErrorSeverity.ERROR), + EMPTY_STRINGS_NOT_ALLOWED(174, "string literals cannot be empty", ErrorSeverity.ERROR), /* * Backward incompatibility errors