Open
Conversation
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.a*bexprwhereaandbare optional.*<n,m>wherenandmare optional.:(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.