From 9aab3380219e94dd9b8b5aa57ce8a53c90b4c69a Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Tue, 29 Nov 2016 19:12:43 +0300 Subject: [PATCH] Reverted old error types and numbers. --- .../antlr/v4/test/tool/TestSymbolIssues.java | 20 ++++---- .../v4/test/tool/TestToolSyntaxErrors.java | 6 +-- .../antlr/v4/automata/LexerATNFactory.java | 16 ++++++- .../antlr/v4/semantics/SemanticPipeline.java | 2 +- .../org/antlr/v4/semantics/SymbolChecks.java | 4 +- tool/src/org/antlr/v4/tool/ErrorType.java | 48 ++++++++++++++++--- 6 files changed, 72 insertions(+), 24 deletions(-) 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 1c31749a9..e591a986b 100644 --- a/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java +++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java @@ -127,7 +127,7 @@ public class TestSymbolIssues extends BaseJavaToolTest { "M1: 'b';\n", // YIELDS - "error(" + ErrorType.DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): F.g4:3:0: cannot declare mode, token or channel with reserved name M1\n" + "error(" + ErrorType.MODE_CONFLICTS_WITH_TOKEN.code + "): F.g4:3:0: mode M1 conflicts with token with same name\n" }; @Before @@ -204,9 +204,9 @@ public class TestSymbolIssues extends BaseJavaToolTest { "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.DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:4:0: cannot declare mode, token or channel with reserved name MAX_CHAR_VALUE\n" + - "error(" + ErrorType.DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:11: cannot declare mode, token or channel with reserved name SKIP\n" + - "error(" + ErrorType.DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS.code + "): L.g4:2:17: cannot declare mode, token or 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); @@ -222,9 +222,9 @@ public class TestSymbolIssues extends BaseJavaToolTest { "E: 'e' -> type(EOF);\n" + "F: 'f' -> pushMode(DEFAULT_MODE);", - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): L.g4:2:18: rule A contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n" + - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): L.g4:3:15: rule B contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n" + - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): L.g4:4:15: rule C contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\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); @@ -240,9 +240,9 @@ public class TestSymbolIssues extends BaseJavaToolTest { "mode MODE1;\n" + "MODE1_TOKEN: 'qwer';", - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): L.g4:4:22: rule TOKEN contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n" + - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): L.g4:4:41: rule TOKEN contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n" + - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): L.g4:4:54: rule TOKEN contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n" + "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): L.g4:4:22: rule TOKEN contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n" + + "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): L.g4:4:41: rule TOKEN contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n" + + "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): L.g4:4:54: rule TOKEN contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\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 3b71460a9..c22d170ac 100644 --- a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java +++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java @@ -657,8 +657,8 @@ public class TestToolSyntaxErrors extends BaseJavaToolTest { "WHITESPACE: [ \\t]+ -> channel(WHITESPACE_CHANNEL);\n"; String expected = - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): T.g4:10:35: rule COMMENT contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n" + - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): T.g4:11:35: rule WHITESPACE contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n" + + "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): T.g4:10:35: rule COMMENT contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n" + + "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): T.g4:11:35: rule WHITESPACE contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n" + "error(" + ErrorType.CHANNELS_BLOCK_IN_COMBINED_GRAMMAR.code + "): T.g4:3:0: custom channels are not supported in combined grammars\n"; String[] pair = { grammar, expected }; @@ -686,7 +686,7 @@ public class TestToolSyntaxErrors extends BaseJavaToolTest { // WHITESPACE_CHANNEL and COMMENT_CHANNEL are defined, but NEWLINE_CHANNEL is not String expected = - "warning(" + ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT.code + "): T.g4:10:34: rule NEWLINE contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output\n"; + "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): T.g4:10:34: rule NEWLINE contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n"; String[] pair = { grammar, expected }; super.testErrors(pair, true); diff --git a/tool/src/org/antlr/v4/automata/LexerATNFactory.java b/tool/src/org/antlr/v4/automata/LexerATNFactory.java index b9fec8abd..979d8d3ab 100644 --- a/tool/src/org/antlr/v4/automata/LexerATNFactory.java +++ b/tool/src/org/antlr/v4/automata/LexerATNFactory.java @@ -465,6 +465,10 @@ public class LexerATNFactory extends ParserATNFactory { if (mode >= 0) { return mode; } + else if (COMMON_CONSTANTS.containsKey(modeName)) { + g.tool.errMgr.grammarError(ErrorType.MODE_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, token, token.getText()); + return null; + } return tryParseInt(modeName, token); } @@ -482,6 +486,10 @@ public class LexerATNFactory extends ParserATNFactory { if (tokenType != org.antlr.v4.runtime.Token.INVALID_TYPE) { return tokenType; } + else if (COMMON_CONSTANTS.containsKey(tokenName)) { + g.tool.errMgr.grammarError(ErrorType.TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, token, token.getText()); + return null; + } return tryParseInt(tokenName, token); } @@ -494,9 +502,13 @@ public class LexerATNFactory extends ParserATNFactory { if (channelName.equals("HIDDEN")) { return Lexer.HIDDEN; } - if (channelName.equals("DEFAULT_TOKEN_CHANNEL")) { + else if (channelName.equals("DEFAULT_TOKEN_CHANNEL")) { return Lexer.DEFAULT_TOKEN_CHANNEL; } + else if (COMMON_CONSTANTS.containsKey(channelName)) { + g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, token, token.getText()); + return null; + } int channelValue = g.getChannelValue(channelName); if (channelValue >= org.antlr.v4.runtime.Token.MIN_USER_CHANNEL_VALUE) { @@ -510,7 +522,7 @@ public class LexerATNFactory extends ParserATNFactory { try { return Integer.parseInt(name); } catch (NumberFormatException ex) { - g.tool.errMgr.grammarError(ErrorType.UNKNOWN_OR_WRONG_LEXER_CONSTANT, g.fileName, token, currentRule.name, token != null ? token.getText() : null); + g.tool.errMgr.grammarError(ErrorType.UNKNOWN_LEXER_CONSTANT, g.fileName, token, currentRule.name, token != null ? token.getText() : null); return null; } } diff --git a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java index f818be742..bc11fc811 100644 --- a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java +++ b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java @@ -293,7 +293,7 @@ public class SemanticPipeline { } if (LexerATNFactory.COMMON_CONSTANTS.containsKey(channelName)) { - g.tool.errMgr.grammarError(ErrorType.DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, channel.token, channelName); + g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, channel.token, channelName); } if (outermost instanceof LexerGrammar) { diff --git a/tool/src/org/antlr/v4/semantics/SymbolChecks.java b/tool/src/org/antlr/v4/semantics/SymbolChecks.java index 0249d5aa7..999d9f0b2 100644 --- a/tool/src/org/antlr/v4/semantics/SymbolChecks.java +++ b/tool/src/org/antlr/v4/semantics/SymbolChecks.java @@ -278,12 +278,12 @@ public class SymbolChecks { for (String modeName : lexerGrammar.modes.keySet()) { if (!modeName.equals("DEFAULT_MODE") && reservedNames.contains(modeName)) { Rule rule = lexerGrammar.modes.get(modeName).iterator().next(); - g.tool.errMgr.grammarError(ErrorType.DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, rule.ast.parent.getToken(), modeName); + g.tool.errMgr.grammarError(ErrorType.MODE_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, rule.ast.parent.getToken(), modeName); } if (g.getTokenType(modeName) != Token.INVALID_TYPE) { Rule rule = lexerGrammar.modes.get(modeName).iterator().next(); - g.tool.errMgr.grammarError(ErrorType.DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, rule.ast.parent.getToken(), modeName); + g.tool.errMgr.grammarError(ErrorType.MODE_CONFLICTS_WITH_TOKEN, g.fileName, rule.ast.parent.getToken(), modeName); } } } diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index 1526a632c..28f78f90f 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -831,7 +831,7 @@ public enum ErrorType { * * @since 4.2 */ - UNKNOWN_OR_WRONG_LEXER_CONSTANT(155, "rule contains a lexer command with an unrecognized or wrong 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. * @@ -960,21 +960,57 @@ public enum ErrorType { /** * Compiler Error 170. * - *

can not declare mode, token or channel with reserved name

+ *
+	 * mode M1;
+	 * A1: 'a'; // ok
+	 * mode M2;
+	 * A2: 'a'; // ok
+	 * M1: 'b'; // error 170
+	 * 
* - *

Reserved names: HIDDEN, DEFAULT_TOKEN_CHANNEL, DEFAULT_MODE, SKIP, MORE, EOF, MAX_CHAR_VALUE, MIN_CHAR_VALUE. + *

mode name conflicts with token with same name

*/ - DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS(170, "cannot declare mode, token or channel with reserved name ", ErrorSeverity.ERROR), + MODE_CONFLICTS_WITH_TOKEN(170, "mode conflicts with token with same name", ErrorSeverity.ERROR), /** * Compiler Error 171. * - *

string literals cannot be empty

+ *

can not use or declare token with reserved name

+ * + *

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

Can be used but cannot be declared: EOF

+ */ + TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS(171, "cannot use or declare token with reserved name ", ErrorSeverity.ERROR), + /** + * Compiler Error 172. + * + *

can not use or declare channel with reserved name

+ * + *

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

Can be used but cannot be declared: HIDDEN, DEFAULT_TOKEN_CHANNEL

+ */ + CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS(172, "cannot use or declare channel with reserved name ", ErrorSeverity.ERROR), + /** + * Compiler Error 173. + * + *

can not use or declare mode with reserved name

+ * + *

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

Can be used and cannot declared: DEFAULT_MODE

+ */ + MODE_CONFLICTS_WITH_COMMON_CONSTANTS(173, "cannot use or declare mode with reserved name ", ErrorSeverity.ERROR), + /** + * Compiler Error 174. + * + *

empty strings not allowed

* *
A: '''test''';
*
B: '';
*
C: 'test' '';
*/ - EMPTY_STRINGS_NOT_ALLOWED(171, "string literals cannot be empty", ErrorSeverity.ERROR), + EMPTY_STRINGS_NOT_ALLOWED(174, "string literals cannot be empty", ErrorSeverity.ERROR), /* * Backward incompatibility errors