Skip to content

Add support for easier handling of ambiguous trees #2579

@PieterOlivier

Description

@PieterOlivier

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions