Navigation Menu

Skip to content
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

Do we support regex matching nested in structures? #201

Closed
JLHwung opened this issue Jun 16, 2021 · 3 comments
Closed

Do we support regex matching nested in structures? #201

JLHwung opened this issue Jun 16, 2021 · 3 comments
Labels

Comments

@JLHwung
Copy link
Contributor

JLHwung commented Jun 16, 2021

The readme example has

match (arithmeticStr) {
  when (/(?<left>\d+) \+ (?<right>\d+)/) as { groups: { left, right } } { process(left, right); }
  else { ... }
}

where the as { groups: { left, right } } is after when ( ... ). However, I think it should have been

match (arithmeticStr) {
  when (/(?<left>\d+) \+ (?<right>\d+)/ as { groups: { left, right } } )  { process(left, right); }
  else { ... }
}

since it can be extended for nested cases:

match (res) {
  when ({
    input: /(?<left>\d+) \+ (?<right>\d+)/) as { groups: { left, right } },
    direction: 'N' | 'S' | 'W' | 'E',
  }) { process(left, right, direction); }
  else { ... }
}
@ljharb
Copy link
Member

ljharb commented Jun 16, 2021

Your first two examples seem equivalent to me, so I'm not sure how "should have" figures in. Can you elaborate?

(your third example should certainly work as-is)

@mpcsh
Copy link
Member

mpcsh commented Jun 16, 2021

I do want to note that there is some debate on the semantics of as and with - see #188 for more context. Do some of the code samples in this comment clear things up for you?

@JLHwung
Copy link
Contributor Author

JLHwung commented Jun 18, 2021

@mpcsh @ljharb Thanks! I confused as with with in previous examples. #188 (comment) works for me.

@JLHwung JLHwung closed this as completed Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants