10000 Multiple variable pattern support · Issue #1061 · lalrpop/lalrpop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Multiple variable pattern support #1061

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
A4-Tacks opened this issue May 4, 2025 · 3 comments
Open

Multiple variable pattern support #1061

A4-Tacks opened this issue May 4, 2025 · 3 comments

Comments

@A4-Tacks
Copy link
Contributor
A4-Tacks commented May 4, 2025
grammar;

Or<A, B> = { A B, B A }
pub Foo: String = <x:Or<"a", "b">> => {
    let (a, b) = x;
    a.to_string() + b
};

Rewritten to:

grammar;

Or<A, B> = { A B, B A }
pub Foo: String = <(a, b):Or<"a", "b">> => {
    a.to_string() + b
};

And support such as <(mut a, b):Bar>, <(a, (b, c)):Baz>

@chanbengz
Copy link
Contributor

LALRPOP supports a shorthand <>. See https://lalrpop.github.io/lalrpop/tutorial/003_type_inference.html.

I would suggest using that

grammar;

Or<A, B> = { A B, B A }
pub Foo: String = Or<"a", "b"> => {
    format!("{}{}", <>.0, <>.1)
};

And support such as <(mut a, b):Bar>, <(a, (b, c)):Baz>

I see your point, but IMO this is weird because <> simply solves the problem. The only problem is that it might not be so "readable".

@A4-Tacks
Copy link
Contributor Author
A4-Tacks commented May 4, 2025

When containing deep nesting, it is very difficult to read without using patterns to untangle it

@dburgener
Copy link
Contributor

I think that having support for this added syntax would be a value-add, although as @chanbengz points out, there are existing ways to express this situation pretty well.

I would say that I'm certainly open to accepting PRs that add this syntax if someone wants to submit one.

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

No branches or pull requests

3 participants
0