Reverted old error types and numbers.

This commit is contained in:
Ivan Kochurkin 2016-11-29 19:12:43 +03:00
parent a1def96500
commit 9aab338021
6 changed files with 72 additions and 24 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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);
}
}
}

View File

@ -831,7 +831,7 @@ public enum ErrorType {
*
* @since 4.2
*/
UNKNOWN_OR_WRONG_LEXER_CONSTANT(155, "rule <arg> contains a lexer command with an unrecognized or wrong constant value; lexer interpreters may produce incorrect output", ErrorSeverity.WARNING),
UNKNOWN_LEXER_CONSTANT(155, "rule <arg> 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.
*
* <p>can not declare mode, token or channel with reserved name</p>
* <pre>
* mode M1;
* A1: 'a'; // ok
* mode M2;
* A2: 'a'; // ok
* M1: 'b'; // error 170
* </pre>
*
* <p>Reserved names: HIDDEN, DEFAULT_TOKEN_CHANNEL, DEFAULT_MODE, SKIP, MORE, EOF, MAX_CHAR_VALUE, MIN_CHAR_VALUE.
* <p>mode <em>name</em> conflicts with token with same name</p>
*/
DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS(170, "cannot declare mode, token or channel with reserved name <arg>", ErrorSeverity.ERROR),
MODE_CONFLICTS_WITH_TOKEN(170, "mode <arg> conflicts with token with same name", ErrorSeverity.ERROR),
/**
* Compiler Error 171.
*
* <p>string literals cannot be empty</p>
* <p>can not use or declare token with reserved name</p>
*
* <p>Reserved names: HIDDEN, DEFAULT_TOKEN_CHANNEL, SKIP, MORE, MAX_CHAR_VALUE, MIN_CHAR_VALUE.
*
* <p>Can be used but cannot be declared: EOF</p>
*/
TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS(171, "cannot use or declare token with reserved name <arg>", ErrorSeverity.ERROR),
/**
* Compiler Error 172.
*
* <p>can not use or declare channel with reserved name</p>
*
* <p>Reserved names: DEFAULT_MODE, SKIP, MORE, EOF, MAX_CHAR_VALUE, MIN_CHAR_VALUE.
*
* <p>Can be used but cannot be declared: HIDDEN, DEFAULT_TOKEN_CHANNEL</p>
*/
CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS(172, "cannot use or declare channel with reserved name <arg>", ErrorSeverity.ERROR),
/**
* Compiler Error 173.
*
* <p>can not use or declare mode with reserved name</p>
*
* <p>Reserved names: HIDDEN, DEFAULT_TOKEN_CHANNEL, SKIP, MORE, MAX_CHAR_VALUE, MIN_CHAR_VALUE.
*
* <p>Can be used and cannot declared: DEFAULT_MODE</p>
*/
MODE_CONFLICTS_WITH_COMMON_CONSTANTS(173, "cannot use or declare mode with reserved name <arg>", ErrorSeverity.ERROR),
/**
* Compiler Error 174.
*
* <p>empty strings not allowed</p>
*
* <pre>A: '''test''';</pre>
* <pre>B: '';</pre>
* <pre>C: 'test' '';</pre>
*/
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