forked from jasder/antlr
Merge branch 'command_wrong_id_1411' into duplicated_and_nonsensical_commands_1388
# Conflicts: # tool/src/org/antlr/v4/tool/ErrorType.java
This commit is contained in:
commit
0e1b5d9d7a
|
@ -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"
|
||||
"error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_TOKEN_NAME.code + "): L.g4:4:22: CHANNEL1 is not a recognized token name\n" +
|
||||
"error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): L.g4:4:41: MODE1 is not a recognized channel name\n" +
|
||||
"error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_MODE_NAME.code + "): L.g4:4:54: TOKEN1 is not a recognized mode name\n"
|
||||
};
|
||||
|
||||
testErrors(test, false);
|
||||
|
|
|
@ -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" +
|
||||
"error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): T.g4:10:35: COMMENT_CHANNEL is not a recognized channel name\n" +
|
||||
"error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): T.g4:11:35: WHITESPACE_CHANNEL is not a recognized channel name\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";
|
||||
"error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): T.g4:10:34: NEWLINE_CHANNEL is not a recognized channel name\n";
|
||||
|
||||
String[] pair = { grammar, expected };
|
||||
super.testErrors(pair, true);
|
||||
|
|
|
@ -516,8 +516,17 @@ 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);
|
||||
try {
|
||||
return Integer.parseInt(modeName);
|
||||
} catch (NumberFormatException ex) {
|
||||
g.tool.errMgr.grammarError(ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_MODE_NAME, g.fileName, token, token.getText());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getTokenConstantValue(String tokenName, Token token) {
|
||||
|
@ -533,8 +542,17 @@ 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);
|
||||
try {
|
||||
return Integer.parseInt(tokenName);
|
||||
} catch (NumberFormatException ex) {
|
||||
g.tool.errMgr.grammarError(ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_TOKEN_NAME, g.fileName, token, token.getText());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getChannelConstantValue(String channelName, Token token) {
|
||||
|
@ -545,23 +563,23 @@ 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) {
|
||||
return channelValue;
|
||||
}
|
||||
|
||||
return tryParseInt(channelName, token);
|
||||
}
|
||||
|
||||
private Integer tryParseInt(String name, Token token) {
|
||||
try {
|
||||
return Integer.parseInt(name);
|
||||
return Integer.parseInt(channelName);
|
||||
} 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.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME, g.fileName, token, token.getText());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -278,7 +278,7 @@ 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) {
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -972,38 +972,85 @@ public enum ErrorType {
|
|||
*/
|
||||
MODE_CONFLICTS_WITH_TOKEN(170, "mode <arg> conflicts with token with same name", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 171.
|
||||
* Compiler Error 172.
|
||||
*
|
||||
* <p>can not declare mode, token or channel with reserved name</p>
|
||||
* <p>can not use or declare token with reserved name</p>
|
||||
*
|
||||
* <p>Reserved names: HIDDEN, DEFAULT_TOKEN_CHANNEL, DEFAULT_MODE, SKIP, MORE, EOF, MAX_CHAR_VALUE, MIN_CHAR_VALUE.
|
||||
* <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>
|
||||
*/
|
||||
DECLARATION_CONFLICTS_WITH_COMMON_CONSTANTS(171, "cannot declare mode, token or channel with reserved name <arg>", ErrorSeverity.ERROR),
|
||||
TOKEN_CONFLICTS_WITH_COMMON_CONSTANTS(171, "cannot use or declare token with reserved name <arg>", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 172.
|
||||
*
|
||||
* <p>string literals cannot be empty</p>
|
||||
* <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(172, "string literals cannot be empty", ErrorSeverity.ERROR),
|
||||
EMPTY_STRINGS_NOT_ALLOWED(174, "string literals cannot be empty", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 175.
|
||||
*
|
||||
* <p><em>name</em> is not a recognized token name</p>
|
||||
*
|
||||
* <pre>TOKEN: 'a' -> type(CHANNEL1); // error 175</pre>
|
||||
*/
|
||||
CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_TOKEN_NAME(175, "<arg> is not a recognized token name", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 176.
|
||||
*
|
||||
* <p><em>name</em>is not a recognized mode name</p>
|
||||
*
|
||||
* <pre>TOKEN: 'a' -> channel(MODE1); // error 176</pre>
|
||||
*/
|
||||
CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_MODE_NAME(176, "<arg> is not a recognized mode name", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 177.
|
||||
*
|
||||
* <p><em>name</em> is not a recognized channel name</p>
|
||||
*
|
||||
* <pre>TOKEN: 'a' -> mode(TOKEN1); // error 177</pre>
|
||||
*/
|
||||
CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME(177, "<arg> is not a recognized channel name", ErrorSeverity.ERROR),
|
||||
/*
|
||||
* Compiler Warning 173.
|
||||
* Compiler Warning 178.
|
||||
*
|
||||
* <p>lexer rule has a duplicated commands</p>
|
||||
*
|
||||
* <p>TOKEN: 'asdf' -> mode(MODE1), mode(MODE2);</p>
|
||||
* */
|
||||
DUPLICATED_COMMAND(173, "duplicated command <arg>", ErrorSeverity.WARNING),
|
||||
/* Compiler Waring 174.
|
||||
DUPLICATED_COMMAND(178, "duplicated command <arg>", ErrorSeverity.WARNING),
|
||||
/*
|
||||
* Compiler Waring 179.
|
||||
*
|
||||
* <p>incompatible commands <em>command1</em> and <em>command2</em></p>
|
||||
*
|
||||
* <p>T00: 'a00' -> skip, more;</p>
|
||||
*/
|
||||
INCOMPATIBLE_COMMANDS(174, "incompatible commands <arg> and <arg2>", ErrorSeverity.WARNING),
|
||||
INCOMPATIBLE_COMMANDS(179, "incompatible commands <arg> and <arg2>", ErrorSeverity.WARNING),
|
||||
|
||||
/*
|
||||
* Backward incompatibility errors
|
||||
|
|
Loading…
Reference in New Issue