got more tests in; about to refactor resolving.
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6697]
This commit is contained in:
parent
29c602c202
commit
9c8e4380fc
|
@ -103,6 +103,9 @@ public class AttributeChecks implements ActionSplitterListener {
|
|||
|
||||
public void attr(String expr, Token x) { // arg, retval, predefined, token ref, rule ref, current rule
|
||||
if ( node.resolver.resolveToAttribute(x.getText(), node)==null ) {
|
||||
if ( node.resolver.resolveToScope(x.getText(), node)!=null ) {
|
||||
return; // $S for scope S is ok
|
||||
}
|
||||
if ( node.resolver.resolveToRule(x.getText(), node)!=null ) { // or in rule and is rule ref
|
||||
ErrorManager.grammarError(ErrorType.ISOLATED_RULE_SCOPE,
|
||||
g.fileName, x, x.getText(), expr);
|
||||
|
@ -137,21 +140,25 @@ public class AttributeChecks implements ActionSplitterListener {
|
|||
public void setDynamicNegativeIndexedScopeAttr(String expr, Token x, Token y,
|
||||
Token index, Token rhs) {
|
||||
setDynamicScopeAttr(expr, x, y, rhs);
|
||||
new AttributeChecks(g, r, alt, node, index).examineAction();
|
||||
}
|
||||
|
||||
public void dynamicNegativeIndexedScopeAttr(String expr, Token x, Token y,
|
||||
Token index) {
|
||||
dynamicScopeAttr(expr, x, y);
|
||||
new AttributeChecks(g, r, alt, node, index).examineAction();
|
||||
}
|
||||
|
||||
public void setDynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y,
|
||||
Token index, Token rhs) {
|
||||
setDynamicScopeAttr(expr, x, y, rhs);
|
||||
new AttributeChecks(g, r, alt, node, index).examineAction();
|
||||
}
|
||||
|
||||
public void dynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y,
|
||||
Token index) {
|
||||
dynamicScopeAttr(expr, x, y);
|
||||
new AttributeChecks(g, r, alt, node, index).examineAction();
|
||||
}
|
||||
|
||||
public void unknownSyntax(String text) {
|
||||
|
|
|
@ -14,6 +14,7 @@ public class TestAttributeChecks extends BaseTest {
|
|||
" : lab=b[34] {\n" +
|
||||
" <inline>\n" +
|
||||
" }\n" +
|
||||
" c\n" +
|
||||
" ;\n" +
|
||||
" finally {<finally>}\n" +
|
||||
"b[int d] returns [int e]\n" +
|
||||
|
@ -46,11 +47,16 @@ public class TestAttributeChecks extends BaseTest {
|
|||
};
|
||||
|
||||
String[] initChecks = {
|
||||
"$a", "error(33): A.g:4:8: missing attribute access on rule reference a in $a",
|
||||
"$a", "", // a has scope
|
||||
"$c", "error(29): A.g:4:8: unknown attribute reference c in $c",
|
||||
"$a.q", "error(31): A.g:4:10: unknown attribute rule q in $a.q",
|
||||
};
|
||||
|
||||
String[] inlineChecks = {
|
||||
"$a", "",
|
||||
"$b", "", // b has scope
|
||||
"$lab", "",
|
||||
"$c", "error(29): A.g:6:4: unknown attribute reference c in $c", // no scope
|
||||
"$q", "error(29): A.g:6:4: unknown attribute reference q in $q",
|
||||
"$q.y", "error(29): A.g:6:4: unknown attribute reference q in $q.y",
|
||||
"$q = 3", "error(29): A.g:6:4: unknown attribute reference q in $q",
|
||||
|
@ -58,17 +64,16 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$q.y = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q.y = 3;",
|
||||
"$q = $blort;", "error(29): A.g:6:4: unknown attribute reference q in $q = $blort;\n" +
|
||||
"error(29): A.g:6:9: unknown attribute reference blort in $blort",
|
||||
"$a", "error(33): A.g:6:4: missing attribute access on rule reference a in $a",
|
||||
"$a.ick", "error(31): A.g:6:6: unknown attribute rule ick in $a.ick",
|
||||
"$a.ick = 3;", "error(31): A.g:6:6: unknown attribute rule ick in $a.ick = 3;",
|
||||
"$b", "error(33): A.g:6:4: missing attribute access on rule reference b in $b",
|
||||
"$b.d", "error(30): A.g:6:6: cannot access rule d's parameter: $b.d", // can't see rule ref's arg
|
||||
"$c.text", "error(29): A.g:6:4: unknown attribute reference c in $c.text", // valid rule, but no ref
|
||||
"$lab", "error(33): A.g:6:4: missing attribute access on rule reference lab in $lab",
|
||||
"$lab.d", "error(31): A.g:6:8: unknown attribute rule d in $lab.d",
|
||||
};
|
||||
|
||||
String[] finallyChecks = {
|
||||
"$lab", "",
|
||||
"$a", "",
|
||||
"$q", "error(29): A.g:8:14: unknown attribute reference q in $q",
|
||||
"$q.y", "error(29): A.g:8:14: unknown attribute reference q in $q.y",
|
||||
"$q = 3", "error(29): A.g:8:14: unknown attribute reference q in $q",
|
||||
|
@ -76,13 +81,11 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$q.y = 3;", "error(29): A.g:8:14: unknown attribute reference q in $q.y = 3;",
|
||||
"$q = $blort;", "error(29): A.g:8:14: unknown attribute reference q in $q = $blort;\n" +
|
||||
"error(29): A.g:8:19: unknown attribute reference blort in $blort",
|
||||
"$a", "error(33): A.g:8:14: missing attribute access on rule reference a in $a",
|
||||
"$a.ick", "error(31): A.g:8:16: unknown attribute rule ick in $a.ick",
|
||||
"$a.ick = 3;", "error(31): A.g:8:16: unknown attribute rule ick in $a.ick = 3;",
|
||||
"$b", "error(29): A.g:8:14: unknown attribute reference b in $b",
|
||||
"$b.d", "error(29): A.g:8:14: unknown attribute reference b in $b.d",
|
||||
"$c.text", "error(29): A.g:8:14: unknown attribute reference c in $c.text",
|
||||
"$lab", "error(33): A.g:8:14: missing attribute access on rule reference lab in $lab",
|
||||
"$lab.d", "error(31): A.g:8:18: unknown attribute rule d in $lab.d",
|
||||
};
|
||||
|
||||
|
@ -104,10 +107,29 @@ public class TestAttributeChecks extends BaseTest {
|
|||
|
||||
String[] dynInlineChecks = {
|
||||
"$b::f", "",
|
||||
"$S", "",
|
||||
|
||||
"$S::j", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j",
|
||||
"$S::j = 3;", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;",
|
||||
"$S::j = $S::k;", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g:9:21: unknown dynamically-scoped attribute for scope S: k in $S::k",
|
||||
"$Q[-1]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-1]::y",
|
||||
"$Q[-i]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-i]::y",
|
||||
"$Q[i]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[i]::y",
|
||||
"$Q[0]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[0]::y",
|
||||
"$Q[-1]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-1]::y = 23;",
|
||||
"$Q[-i]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-i]::y = 23;",
|
||||
"$Q[i]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[i]::y = 23;",
|
||||
"$Q[0]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[0]::y = 23;",
|
||||
"$S[-1]::y", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y",
|
||||
"$S[-i]::y", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y",
|
||||
"$S[i]::y", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[i]::y",
|
||||
"$S[0]::y", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[0]::y",
|
||||
"$S[-1]::y = 23;", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y = 23;",
|
||||
"$S[-i]::y = 23;", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y = 23;",
|
||||
"$S[i]::y = 23;", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[i]::y = 23;",
|
||||
"$S[0]::y = 23;", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[0]::y = 23;",
|
||||
"$S[$S::y]::i", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S::y"
|
||||
};
|
||||
|
||||
String[] dynFinallyChecks = {
|
||||
|
|
Loading…
Reference in New Issue