From 19f861ee8117826f09d2a2d2f69246582e14bea9 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Thu, 10 Jan 2013 14:46:52 -0600 Subject: [PATCH] Added error message 135: cannot assign a value to list label: $label --- tool/src/org/antlr/v4/semantics/AttributeChecks.java | 8 +++++++- tool/src/org/antlr/v4/tool/ErrorType.java | 1 + tool/test/org/antlr/v4/test/TestAttributeChecks.java | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tool/src/org/antlr/v4/semantics/AttributeChecks.java b/tool/src/org/antlr/v4/semantics/AttributeChecks.java index 7335c8839..94c48ea45 100644 --- a/tool/src/org/antlr/v4/semantics/AttributeChecks.java +++ b/tool/src/org/antlr/v4/semantics/AttributeChecks.java @@ -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(); diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index ce0bb066a..42896ef5d 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -115,6 +115,7 @@ public enum ErrorType { LEXER_COMMAND_PLACEMENT_ISSUE(133, "->command in lexer rule must be last element of single outermost alt", ErrorSeverity.ERROR), USE_OF_BAD_WORD(134, "symbol conflicts with generated code in target language or runtime", ErrorSeverity.ERROR), INVALID_LEXER_SET_ELEMENT(134, "lexer set element 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: $", ErrorSeverity.ERROR), // Backward incompatibility errors V3_TREE_GRAMMAR(200, "tree grammars are not supported in ANTLR 4", ErrorSeverity.ERROR), diff --git a/tool/test/org/antlr/v4/test/TestAttributeChecks.java b/tool/test/org/antlr/v4/test/TestAttributeChecks.java index 6ea490de0..95c03f806 100644 --- a/tool/test/org/antlr/v4/test/TestAttributeChecks.java +++ b/tool/test/org/antlr/v4/test/TestAttributeChecks.java @@ -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 = {