forked from jasder/antlr
Merge pull request #630 from sharwell/fix-571
Remove ability to reference enclosing rule by name, in favor of $ctx
This commit is contained in:
commit
17128d6486
|
@ -92,7 +92,6 @@ public class Alternative implements AttributeResolver {
|
||||||
if ( ruleRefs.get(x)!=null ) return true; // rule ref in this alt?
|
if ( ruleRefs.get(x)!=null ) return true; // rule ref in this alt?
|
||||||
LabelElementPair anyLabelDef = getAnyLabelDef(x);
|
LabelElementPair anyLabelDef = getAnyLabelDef(x);
|
||||||
if ( anyLabelDef!=null && anyLabelDef.type==LabelType.RULE_LABEL ) return true;
|
if ( anyLabelDef!=null && anyLabelDef.type==LabelType.RULE_LABEL ) return true;
|
||||||
if ( x.equals(rule.name) ) return true; // $r for action in rule r, $r is a dict
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +107,6 @@ public class Alternative implements AttributeResolver {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Attribute resolveToAttribute(String x, String y, ActionAST node) {
|
public Attribute resolveToAttribute(String x, String y, ActionAST node) {
|
||||||
if ( rule.name.equals(x) ) { // x is this rule?
|
|
||||||
return rule.resolveToAttribute(x, y, node);
|
|
||||||
}
|
|
||||||
if ( tokenRefs.get(x)!=null ) { // token ref in this alt?
|
if ( tokenRefs.get(x)!=null ) { // token ref in this alt?
|
||||||
return rule.getPredefinedScope(LabelType.TOKEN_LABEL).get(y);
|
return rule.getPredefinedScope(LabelType.TOKEN_LABEL).get(y);
|
||||||
}
|
}
|
||||||
|
@ -162,7 +158,6 @@ public class Alternative implements AttributeResolver {
|
||||||
if ( anyLabelDef!=null && anyLabelDef.type==LabelType.RULE_LABEL ) {
|
if ( anyLabelDef!=null && anyLabelDef.type==LabelType.RULE_LABEL ) {
|
||||||
return rule.g.getRule(anyLabelDef.element.getText());
|
return rule.g.getRule(anyLabelDef.element.getText());
|
||||||
}
|
}
|
||||||
if ( x.equals(rule.name) ) return rule;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,9 +259,6 @@ public class Rule implements AttributeResolver {
|
||||||
/** $x.y Attribute: x is surrounding rule, label ref (in any alts) */
|
/** $x.y Attribute: x is surrounding rule, label ref (in any alts) */
|
||||||
@Override
|
@Override
|
||||||
public Attribute resolveToAttribute(String x, String y, ActionAST node) {
|
public Attribute resolveToAttribute(String x, String y, ActionAST node) {
|
||||||
if ( this.name.equals(x) ) { // x is this rule?
|
|
||||||
return resolveToAttribute(y, node);
|
|
||||||
}
|
|
||||||
LabelElementPair anyLabelDef = getAnyLabelDef(x);
|
LabelElementPair anyLabelDef = getAnyLabelDef(x);
|
||||||
if ( anyLabelDef!=null ) {
|
if ( anyLabelDef!=null ) {
|
||||||
if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
|
if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
|
||||||
|
@ -306,7 +303,6 @@ public class Rule implements AttributeResolver {
|
||||||
@Override
|
@Override
|
||||||
public boolean resolvesToAttributeDict(String x, ActionAST node) {
|
public boolean resolvesToAttributeDict(String x, ActionAST node) {
|
||||||
if ( resolvesToToken(x, node) ) return true;
|
if ( resolvesToToken(x, node) ) return true;
|
||||||
if ( x.equals(name) ) return true; // $r for action in rule r, $r is a dict
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,25 +119,25 @@ public class TestActionTranslation extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testArguments() throws Exception {
|
@Test public void testArguments() throws Exception {
|
||||||
String action = "$x; $a.x";
|
String action = "$x; $ctx.x";
|
||||||
String expected = "_localctx.x; _localctx.x";
|
String expected = "_localctx.x; _localctx.x";
|
||||||
testActions(attributeTemplate, "inline", action, expected);
|
testActions(attributeTemplate, "inline", action, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testReturnValue() throws Exception {
|
@Test public void testReturnValue() throws Exception {
|
||||||
String action = "$x; $a.x";
|
String action = "$y; $ctx.y";
|
||||||
String expected = "_localctx.x; _localctx.x";
|
String expected = "_localctx.y; _localctx.y";
|
||||||
testActions(attributeTemplate, "inline", action, expected);
|
testActions(attributeTemplate, "inline", action, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testReturnValueWithNumber() throws Exception {
|
@Test public void testReturnValueWithNumber() throws Exception {
|
||||||
String action = "$a.x1";
|
String action = "$ctx.x1";
|
||||||
String expected = "_localctx.x1";
|
String expected = "_localctx.x1";
|
||||||
testActions(attributeTemplate, "inline", action, expected);
|
testActions(attributeTemplate, "inline", action, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testReturnValuesCurrentRule() throws Exception {
|
@Test public void testReturnValuesCurrentRule() throws Exception {
|
||||||
String action = "$y; $a.y;";
|
String action = "$y; $ctx.y;";
|
||||||
String expected = "_localctx.y; _localctx.y;";
|
String expected = "_localctx.y; _localctx.y;";
|
||||||
testActions(attributeTemplate, "inline", action, expected);
|
testActions(attributeTemplate, "inline", action, expected);
|
||||||
}
|
}
|
||||||
|
@ -167,11 +167,11 @@ public class TestActionTranslation extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testRefToTextAttributeForCurrentRule() throws Exception {
|
@Test public void testRefToTextAttributeForCurrentRule() throws Exception {
|
||||||
String action = "$a.text; $text";
|
String action = "$ctx.text; $text";
|
||||||
|
|
||||||
// this is the expected translation for all cases
|
// this is the expected translation for all cases
|
||||||
String expected =
|
String expected =
|
||||||
"_input.getText(_localctx.start, _input.LT(-1)); _input.getText(_localctx.start, _input.LT(-1))";
|
"_localctx.text; _input.getText(_localctx.start, _input.LT(-1))";
|
||||||
|
|
||||||
testActions(attributeTemplate, "init", action, expected);
|
testActions(attributeTemplate, "init", action, expected);
|
||||||
testActions(attributeTemplate, "inline", action, expected);
|
testActions(attributeTemplate, "inline", action, expected);
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class TestAttributeChecks extends BaseTest {
|
||||||
"$x = $y", "",
|
"$x = $y", "",
|
||||||
"$y = $x", "",
|
"$y = $x", "",
|
||||||
"$y.b = 3;", "",
|
"$y.b = 3;", "",
|
||||||
"$a.x = $a.y", "",
|
"$ctx.x = $ctx.y", "",
|
||||||
"$lab.e", "",
|
"$lab.e", "",
|
||||||
"$lab.text", "",
|
"$lab.text", "",
|
||||||
"$b.e", "",
|
"$b.e", "",
|
||||||
|
|
Loading…
Reference in New Issue