Skip to content
New issue

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

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

Already on GitHub? # to your account

Unit switch with look-ahead cannot be nested #1810

Closed
bbannier opened this issue Jul 26, 2024 · 1 comment · Fixed by #1811
Closed

Unit switch with look-ahead cannot be nested #1810

bbannier opened this issue Jul 26, 2024 · 1 comment · Fixed by #1811
Assignees
Labels
Feature Request Request for new functionality Language

Comments

@bbannier
Copy link
Member

When branching on a value unit switch can be nested, e.g., the following works:

module foo;

public type X = unit(typ: uint8) {
    switch (typ) {
        1 -> switch (typ) {
            1 -> a: b"a";
            2 -> b: b"b";
        };
        3 -> c: b"c";
    };
};

While this would seem contrived it allows collecting related information together which reduces the need to store values if other parsing depends on this.

The same pattern does not seem to work with unit switch with look-ahead, e.g.,

module foo;

public type X = unit(typ: uint8) {
    switch {
        -> switch {
            -> a: b"a";
            -> b: b"b";
        };
        -> c: b"c";
    };

};
$ spicyc -dj foo.spicy
[error] foo.spicy:5:12-5:17: syntax error, unexpected SWITCH
[error] spicyc: parse error
@bbannier bbannier added Feature Request Request for new functionality Language labels Jul 26, 2024
@rsmmr rsmmr self-assigned this Jul 29, 2024
bbannier added a commit to bbannier/tree-sitter-spicy that referenced this issue Jul 29, 2024
This adds support for parsing unit switch with lahead, zeek/spicy#1810.
bbannier added a commit to bbannier/spicy-format that referenced this issue Jul 29, 2024
@rsmmr rsmmr closed this as completed in 215b8bf Jul 30, 2024
rsmmr added a commit that referenced this issue Jul 30, 2024
…witch'

* origin/topic/robin/gh-1810-nested-lah-switch:
  Update CHANGES. [skip ci]
  Fix nested look-ahead switches.
bbannier pushed a commit that referenced this issue Jul 31, 2024
Closes #1810.

(cherry picked from commit 215b8bf)
@bbannier
Copy link
Member Author

Also backported to releases/1.11.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Feature Request Request for new functionality Language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants