Skip to content

Switch to new range syntax#2173

Open
ehuss wants to merge 1 commit intorust-lang:masterfrom
ehuss:new-range-syntax
Open

Switch to new range syntax#2173
ehuss wants to merge 1 commit intorust-lang:masterfrom
ehuss:new-range-syntax

Conversation

@ehuss
Copy link
Contributor

@ehuss ehuss commented Feb 15, 2026

This changes the syntax for range repeat so that it handles inclusive and exclusive upper bounds with ..= and ...

The old syntax was confusing. It used .. for inclusive bound, but that's not how Rust syntax works. This changes it so that it uses ..= for inclusive bounds to be consistent with Rust syntax.

There are some other options for range syntax that I considered:

  • {a,b} which is the syntax used by most regex engines, and some parsers like Pest and Parsimonious.
  • IETF ABNF and W3C EBNF uses a*bexpr where a and b are optional.
  • Peg-rs uses *<n,m> where n and m are optional.
  • Various languages use : (Python, Julia, Excel, etc.) or .. (Rust, Kotlin, Swift, C#, F#, Zig, Perl, etc.) to represent ranges.

This will become more relevant when we switch the raw string literals to use a bounded range. We can't easily avoid the use of bounded repetition because of raw-string's bound of 255. Listing out 255 variants would be just too much, and it is convenient to avoid English-descriptive rules.

This changes the syntax for range repeat so that it handles inclusive
and exclusive upper bounds with `..=` and `..`.

The old syntax was confusing. It used `..` for inclusive bound, but
that's not how Rust syntax works. This changes it so that it uses `..=`
for inclusive bounds to be consistent with Rust syntax.

There are some other options for range syntax that I considered:

- `{a,b}` which is the syntax used by most regex engines, and some
  parsers like Pest and Parsimonious.
- IETF ABNF and W3C EBNF uses `a*bexpr` where `a` and `b` are optional.
- Peg-rs uses `*<n,m>` where `n` and `m` are optional.
- Various languages use `:` (Python, Julia, Excel, etc.) or `..` (Rust,
  Kotlin, Swift, C#, F#, Zig, Perl, etc.) to represent ranges.

This will become more relevant when we switch the raw string literals to
use a bounded range. We can't easily avoid the use of bounded repetition
because of raw-string's bound of 255. Listing out 255 variants would be
just too much, and it is convenient to avoid English-descriptive rules.
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Feb 15, 2026
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