Skip to content

Indexed field assignment on parse trees #2272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
PieterOlivier opened this issue May 27, 2025 · 0 comments
Open

Indexed field assignment on parse trees #2272

PieterOlivier opened this issue May 27, 2025 · 0 comments
Assignees

Comments

@PieterOlivier
Copy link
Contributor

PieterOlivier commented May 27, 2025

You can access parts of a parse tree using indexing, but you cannot assign subtrees using the same method:

module bug::IndexedFieldAssignment

syntax S = A "$";
syntax A = "a" | "A";

import ParseTree;
import IO;

test bool testIndexedFieldAssignment() {
    S s = parse(#S, "a$");
    value a = s[0];
    assert "<a>" == "a";

    s[0] = (A)`A`;
    return "<s>" == "A$";
}

The assertion succeeds but the test fails with an error:

Unsupported subscript of type int on type S
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UnsupportedSubscript|

For the sake of consistency and usefulness of this feature, I think indexed assignment should be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants