Added error message 135: cannot assign a value to list label: $label

This commit is contained in:
Sam Harwell 2013-01-10 14:46:52 -06:00
parent 8d13e3c47e
commit 19f861ee81
3 changed files with 9 additions and 1 deletions

View File

@ -161,7 +161,13 @@ public class AttributeChecks implements ActionSplitterListener {
return;
}
if ( node.resolver.resolveToAttribute(x.getText(), node)==null ) {
errMgr.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE,
ErrorType errorType = ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE;
if ( node.resolver.resolvesToListLabel(x.getText(), node) ) {
// $ids for ids+=ID etc...
errorType = ErrorType.ASSIGNMENT_TO_LIST_LABEL;
}
errMgr.grammarError(errorType,
g.fileName, x, x.getText(), expr);
}
new AttributeChecks(g, r, alt, node, rhs).examineAction();

View File

@ -115,6 +115,7 @@ public enum ErrorType {
LEXER_COMMAND_PLACEMENT_ISSUE(133, "->command in lexer rule <arg> must be last element of single outermost alt", ErrorSeverity.ERROR),
USE_OF_BAD_WORD(134, "symbol <arg> conflicts with generated code in target language or runtime", ErrorSeverity.ERROR),
INVALID_LEXER_SET_ELEMENT(134, "lexer set element <arg> is invalid (either lexer rule ref or literal with > 1 char)", ErrorSeverity.ERROR),
ASSIGNMENT_TO_LIST_LABEL(135, "cannot assign a value to list label: $<arg>", ErrorSeverity.ERROR),
// Backward incompatibility errors
V3_TREE_GRAMMAR(200, "tree grammars are not supported in ANTLR 4", ErrorSeverity.ERROR),

View File

@ -102,6 +102,7 @@ public class TestAttributeChecks extends BaseTest {
"$b.d", "error(64): A.g4:7:6: cannot access rule d's parameter: $b.d\n", // can't see rule ref's arg
"$d.text", "error(63): A.g4:7:4: unknown attribute reference d in $d.text\n", // valid rule, but no ref
"$lab.d", "error(64): A.g4:7:8: cannot access rule d's parameter: $lab.d\n",
"$ids = null;", "error(135): A.g4:7:4: cannot assign a value to list label: $ids\n",
};
String[] finallyChecks = {