-
Notifications
You must be signed in to change notification settings - Fork 82
Description
When a tree is ambigous, field access will fail in the interpeter with a static error (UndeclaredField) that cannot be caught:
module lang::rascal::tests::concrete::recovery::Amb
import ParseTree;
import vis::Text;
import IO;
syntax S = O? A a | A a;
syntax A = "a";
syntax O = "o"?;
void testAmb() {
S s = parse(#S, "a", allowAmbiguity=true);
println(prettyTree(s));
println("a: <s.a>");
}
Gives the output:
rascal>testAmb();
❖
├─ S = A a
│ └─ A = "a"
└─ S = O? A a
├─ ❖
│ ├─ O?
│ └─ O?
│ └─ O = "o"?
│ └─ "o"?
└─ A = "a"
|std:///lang/rascal/tests/concrete/recovery/Amb.rsc|(291,1,<18,17>,<18,18>): Undeclared field: a for Tree
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredField|
This makes it hard to work with ambiguous trees because every access needs to be checked.
We should have a generic way to catch these errors at a higher level, just like we do with errors caused by missing fields in error trees.
For the approach taken with error trees see:
http://www.rascal-mpl.org/docs/RascalAmendmentProposals/RAP16/
We should investigate which of the constructs discussed in the RAP16 are also affected when the tree is ambiguous and come up with a similar solution.
At first glance, field access in ambiguous trees should probably be handled exactly like field access in error trees "after the dot", only with a different wrapping exception to indicate the core cause is an ambiguous tree, not an error tree.