-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #60932 - Centril:macro-at-most-once-2015, r=mark-i-m
Support ? Kleene macro operator in 2015 Closes #56668. See that issue for rationale and discussion. Crater will be needed (done in #60932 (comment), zero regressions) and then, if all goes well, FCP (in #60932 (comment)).
- Loading branch information
Showing
16 changed files
with
281 additions
and
321 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// run-pass | ||
|
||
#![allow(unused_mut)] | ||
|
||
// Check that when `?` is followed by what looks like a Kleene operator (?, +, and *) | ||
// then that `?` is not interpreted as a separator. In other words, `$(pat)?+` matches `pat +` | ||
// or `+` but does not match `pat` or `pat ? pat`. | ||
|
||
// edition:2015 | ||
|
||
macro_rules! foo { | ||
// Check for `?`. | ||
($($a:ident)? ? $num:expr) => { | ||
foo!($($a)? ; $num); | ||
}; | ||
// Check for `+`. | ||
($($a:ident)? + $num:expr) => { | ||
foo!($($a)? ; $num); | ||
}; | ||
// Check for `*`. | ||
($($a:ident)? * $num:expr) => { | ||
foo!($($a)? ; $num); | ||
}; | ||
// Check for `;`, not a kleene operator. | ||
($($a:ident)? ; $num:expr) => { | ||
let mut x = 0; | ||
|
||
$( | ||
x += $a; | ||
)? | ||
|
||
assert_eq!(x, $num); | ||
}; | ||
} | ||
|
||
pub fn main() { | ||
let a = 1; | ||
|
||
// Accept 0 repetitions. | ||
foo!( ; 0); | ||
foo!( + 0); | ||
foo!( * 0); | ||
foo!( ? 0); | ||
|
||
// Accept 1 repetition. | ||
foo!(a ; 1); | ||
foo!(a + 1); | ||
foo!(a * 1); | ||
foo!(a ? 1); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// run-pass | ||
|
||
#![allow(unused_mut)] | ||
|
||
// Check that when `?` is followed by what looks like a Kleene operator (?, +, and *) | ||
// then that `?` is not interpreted as a separator. In other words, `$(pat)?+` matches `pat +` | ||
// or `+` but does not match `pat` or `pat ? pat`. | ||
|
||
// edition:2018 | ||
|
||
macro_rules! foo { | ||
// Check for `?`. | ||
($($a:ident)? ? $num:expr) => { | ||
foo!($($a)? ; $num); | ||
}; | ||
// Check for `+`. | ||
($($a:ident)? + $num:expr) => { | ||
foo!($($a)? ; $num); | ||
}; | ||
// Check for `*`. | ||
($($a:ident)? * $num:expr) => { | ||
foo!($($a)? ; $num); | ||
}; | ||
// Check for `;`, not a kleene operator. | ||
($($a:ident)? ; $num:expr) => { | ||
let mut x = 0; | ||
|
||
$( | ||
x += $a; | ||
)? | ||
|
||
assert_eq!(x, $num); | ||
}; | ||
} | ||
|
||
pub fn main() { | ||
let a = 1; | ||
|
||
// Accept 0 repetitions. | ||
foo!( ; 0); | ||
foo!( + 0); | ||
foo!( * 0); | ||
foo!( ? 0); | ||
|
||
// Accept 1 repetition. | ||
foo!(a ; 1); | ||
foo!(a + 1); | ||
foo!(a * 1); | ||
foo!(a ? 1); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.