Skip to content

Add support for named repeat ranges#2181

Open
ehuss wants to merge 3 commits intorust-lang:masterfrom
ehuss:named-range
Open

Add support for named repeat ranges#2181
ehuss wants to merge 3 commits intorust-lang:masterfrom
ehuss:named-range

Conversation

@ehuss
Copy link
Contributor

@ehuss ehuss commented Feb 18, 2026

This adds the ability to add a label to a repeat range so that a subsequent expression can match the same repetition. This is used in raw strings where the # characters must be balanced on both sides, with a limit on the number of matches.

This also removes the non-greedy repetitions because they are no longer used.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Feb 18, 2026
This adds the ability to add a label to a repeat range so that a
subsequent expression can match the same repetition. This is intended to
help with expressing things like raw strings where the `#` characters
must be balanced on both sides, with a limit on the number of matches.
This changes the raw string grammars to use named repetition to
represent that the `#` characters need to be balanced within a specific
limit.

This also adds a cut after the `#` and before the `"` because rustc
generates an error in this situation if a `"` is not found.

It's maybe not the prettiest, and I'm on the fence whether this makes
it clearer.
These non-greedy repetitions are no longer needed because we now use
negative lookahead in the rules that were using them.

This is intended to simplify things a little, and lean in on the
negative lookahead.

There were two alternate interpretations of `R1 -> A E*? S B`:

R1 -> A _0 B
_0 -> S | (E _0)

or

R1 -> A _0
_0 -> (S B) | (E _0)

Rather than trying to document this subtle interpretation, this chooses
to just get rid of it and be explicit about what is not allowed to
follow.
@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments