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

feat: Add separated_list_m_n #1722

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jtojnar
Copy link

@jtojnar jtojnar commented Jan 22, 2024

This is useful to naïvely represent some grammar productions
(e.g. IPv6address from RFC 3986):

IPv6address /= [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32

turns to

 tuple((
-    opt(tuple((many_m_n(0, 2, tuple((h16, char(':')))), h16))),
+    separated_list_m_n(0, 3, char(':'), h16),
     tag("::"),
     many_m_n(2, 2, tuple((h16, char(':')))),
     ls32,
 ))

@jtojnar jtojnar marked this pull request as ready for review January 22, 2024 17:03
@jtojnar jtojnar requested a review from Geal as a code owner January 22, 2024 17:03
This is useful to naïvely represent some grammar productions
(e.g. `IPv6address` from [RFC 3986]):

```abnf
IPv6address /= [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
```

turns to

```diff
 tuple((
-    opt(tuple((many_m_n(0, 2, tuple((h16, char(':')))), h16))),
+    separated_list_m_n(0, 3, char(':'), h16),
     tag("::"),
     many_m_n(2, 2, tuple((h16, char(':')))),
     ls32,
 ))
```

[RFC 3986]: https://www.rfc-editor.org/rfc/rfc3986#appendix-A
@cenodis
Copy link
Contributor

cenodis commented Mar 14, 2024

Now that #1608 is merged I think it would be better to implement the proper range syntax instead of adding yet another variant for a specific format. Geal has already mentioned seperated_list as a candidate in #1613, so this variant would be made redundant soon anyway.

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

Successfully merging this pull request may close these issues.

None yet

2 participants