This commit is contained in:
parrt 2016-11-22 15:04:28 -08:00
parent dc2c9b039e
commit 6c2d4e6225
3 changed files with 18 additions and 63 deletions

View File

@ -175,6 +175,13 @@ public class TestActionTranslation extends BaseJavaToolTest {
testActions(attributeTemplate, "inline", action, expected); testActions(attributeTemplate, "inline", action, expected);
} }
/** Added in response to https://github.com/antlr/antlr4/issues/1211 */
@Test public void testUnknownAttr() throws Exception {
String action = "$qqq.text";
String expected = ""; // was causing an exception
testActions(attributeTemplate, "inline", action, expected);
}
/** /**
* Regression test for issue #1295 * Regression test for issue #1295
* $e.v yields incorrect value 0 in "e returns [int v] : '1' {$v = 1;} | '(' e ')' {$v = $e.v;} ;" * $e.v yields incorrect value 0 in "e returns [int v] : '1' {$v = 1;} | '(' e ')' {$v = $e.v;} ;"
@ -235,67 +242,7 @@ public class TestActionTranslation extends BaseJavaToolTest {
} }
@Test public void testDynamicRuleScopeRefInSubrule() throws Exception { /*
String action = "$a::n;";
}
@Test public void testRuleScopeFromAnotherRule() throws Exception {
String action = "$a::n;"; // must be qualified
}
@Test public void testFullyQualifiedRefToCurrentRuleParameter() throws Exception {
String action = "$a.i;";
}
@Test public void testFullyQualifiedRefToCurrentRuleRetVal() throws Exception {
String action = "$a.i;";
}
@Test public void testSetFullyQualifiedRefToCurrentRuleRetVal() throws Exception {
String action = "$a.i = 1;";
}
@Test public void testIsolatedRefToCurrentRule() throws Exception {
String action = "$a;";
}
@Test public void testIsolatedRefToRule() throws Exception {
String action = "$x;";
}
@Test public void testFullyQualifiedRefToLabelInCurrentRule() throws Exception {
String action = "$a.x;";
}
@Test public void testFullyQualifiedRefToListLabelInCurrentRule() throws Exception {
String action = "$a.x;"; // must be qualified
}
@Test public void testFullyQualifiedRefToTemplateAttributeInCurrentRule() throws Exception {
String action = "$a.st;"; // can be qualified
}
@Test public void testRuleRefWhenRuleHasScope() throws Exception {
String action = "$b.start;";
}
@Test public void testDynamicScopeRefOkEvenThoughRuleRefExists() throws Exception {
String action = "$b::n;";
}
@Test public void testRefToTemplateAttributeForCurrentRule() throws Exception {
String action = "$st=null;";
}
@Test public void testRefToStartAttributeForCurrentRule() throws Exception {
String action = "$start;";
}
@Test public void testTokenLabelFromMultipleAlts() throws Exception {
String action = "$ID.text;"; // must be qualified
}
@Test public void testRuleLabelFromMultipleAlts() throws Exception {
String action = "$b.text;"; // must be qualified
}
@Test public void testUnqualifiedRuleScopeAttribute() throws Exception {
String action = "$n;"; // must be qualified
}
@Test public void testRuleAndTokenLabelTypeMismatch() throws Exception {
}
@Test public void testListAndTokenLabelTypeMismatch() throws Exception {
}
@Test public void testListAndRuleLabelTypeMismatch() throws Exception {
}
@Test public void testArgReturnValueMismatch() throws Exception {
}
@Test public void testSimplePlusEqualLabel() throws Exception { @Test public void testSimplePlusEqualLabel() throws Exception {
String action = "$ids.size();"; // must be qualified String action = "$ids.size();"; // must be qualified
} }
@ -476,6 +423,6 @@ public class TestActionTranslation extends BaseJavaToolTest {
} }
@Test public void testGenericsAsReturnValue() throws Exception { @Test public void testGenericsAsReturnValue() throws Exception {
} }
*/
// TODO: nonlocal $rule::x // TODO: nonlocal $rule::x
} }

View File

@ -64,7 +64,7 @@ public class TestAttributeChecks extends BaseJavaToolTest {
"c : ;\n"; "c : ;\n";
String[] membersChecks = { String[] membersChecks = {
"$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a\n", "$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a\n",
"$a.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a.y\n", "$a.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a.y\n",
}; };

View File

@ -211,6 +211,14 @@ public class ActionTranslator implements ActionSplitterListener {
return; return;
} }
Attribute a = node.resolver.resolveToAttribute(x.getText(), y.getText(), node); Attribute a = node.resolver.resolveToAttribute(x.getText(), y.getText(), node);
if ( a==null ) {
// Added in response to https://github.com/antlr/antlr4/issues/1211
gen.g.tool.errMgr.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE,
gen.g.fileName, x,
x.getText(),
"rule");
return;
}
switch ( a.dict.type ) { switch ( a.dict.type ) {
case ARG: chunks.add(new ArgRef(nodeContext,y.getText())); break; // has to be current rule case ARG: chunks.add(new ArgRef(nodeContext,y.getText())); break; // has to be current rule
case RET: case RET: