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

Nested Named Patterns/Groups #42

Closed
7fe opened this issue Jul 9, 2017 · 5 comments
Closed

Nested Named Patterns/Groups #42

7fe opened this issue Jul 9, 2017 · 5 comments

Comments

@7fe
Copy link

7fe commented Jul 9, 2017

So there is a proposal currently to get named pattern groups in RegExp. I'm only really familiar with pattern matching in Mathematica so I can't comment on other languages but it would be nice if the proposal supported something like named grouped pattern matching from the get go. Matematica uses : which is kinda taken for obvious reasons. name : pattern.

Basically they are nested. all references the entire array and first references 1. Here is an example using Isiah's syntax.

match ([1,2,3]) {
  all of [first of 1,2,3]: ...
}
@7fe 7fe changed the title Named Patterns/Groups & Questions on Proposal Named Patterns/Groups Jul 9, 2017
@bterlson
Copy link
Member

bterlson commented Jul 21, 2017

This can be accomplished in a few ways:

match (str) {
  // with my proposal in #11
  someRe -> { matches: { name } }: 1

  // with an as/is/of proposal
  is someRe of { matches: { name } }: 1

  // with static support for RegExps which might be neat...
  /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u: year + month + day
}

@rattrayalex
Copy link
Contributor

Static support for RegExps discourages moving them to constants, which is sometimes better code (eg; where the same non-trivial regexp is being used more than once).

Another concern to keep in mind is that if some kind of or support is added, this can get tricky (eg; is someRe or someStr of { matches }: matches.length).

🚲 🏚 – into or with might be nice keywords for this.

@7fe 7fe changed the title Named Patterns/Groups Nested Named Patterns/Groups Jul 23, 2017
@7fe
Copy link
Author

7fe commented Jul 25, 2017

I illustrated with an example which I believe would be valid syntax using Isiah's syntax.

case([1,2,3]) {
  all of [first of 1,2,3] => 
}

@isiahmeadows is this acceptable Isiah?

@dead-claudia
Copy link

@limeblack Close:

case([1,2,3]) {
  all = [first = 1, 2, 3] => ...,
}
  • all is [1, 2, 3]
  • first is 1

Please do familiarize yourself with my proposal, tracked by #17 here. It has a lot of functionality in its syntax.

@zkat
Copy link
Collaborator

zkat commented Mar 25, 2018

Hey y'all! #65 has gotten merged, and a lot of issues have become irrelevant or significantly changed in context. Because of the magnitude of changes and subtle differences in things that seem similar, we've decided to just nuke all existing issues so we can start fresh. Thank you so much for the contributions and discussions and feel free to create new issues if something seems to still be relevant, and link to the original, related issue so we can have a paper trail (but have the benefit of that clean slate anyway).

The new spec -does- talk about everything in this specific issue, though, so I think this can be considered resolved. There's even specific examples using RegExp.

@zkat zkat closed this as completed Mar 25, 2018
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

5 participants