// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// The logic for parsing Kleene operators in macros has a special case to disambiguate `?`.
-// Specifically, `$(pat)?` is the ZeroOrOne operator whereas `$(pat)?+` or `$(pat)?*` are the
-// ZeroOrMore and OneOrMore operators using `?` as a separator. These tests are intended to
-// exercise that logic in the macro parser.
-//
-// Moreover, we also throw in some tests for using a separator with `?`, which is meaningless but
-// included for consistency with `+` and `*`.
-//
-// This test focuses on error cases.
+// Tests the behavior of various Kleene operators in macros with respect to `?` terminals. In
+// particular, `?` in the position of a separator and of a Kleene operator is tested.
#![feature(macro_at_most_once_rep)]
+// should match `` and `a`
macro_rules! foo {
($(a)?) => {}
}
macro_rules! baz {
- ($(a),?) => {} // comma separator is meaningless for `?`
+ ($(a),?) => {} //~ ERROR `?` macro repetition does not allow a separator
}
+// should match `+` and `a+`
macro_rules! barplus {
($(a)?+) => {}
}
+// should match `*` and `a*`
macro_rules! barstar {
($(a)?*) => {}
}
foo!(a?a?a); //~ ERROR no rules expected the token `?`
foo!(a?a); //~ ERROR no rules expected the token `?`
foo!(a?); //~ ERROR no rules expected the token `?`
- baz!(a?a?a); //~ ERROR no rules expected the token `?`
- baz!(a?a); //~ ERROR no rules expected the token `?`
- baz!(a?); //~ ERROR no rules expected the token `?`
- baz!(a,); //~ ERROR unexpected end of macro invocation
- baz!(a?a?a,); //~ ERROR no rules expected the token `?`
- baz!(a?a,); //~ ERROR no rules expected the token `?`
- baz!(a?,); //~ ERROR no rules expected the token `?`
barplus!(); //~ ERROR unexpected end of macro invocation
- barplus!(a?); //~ ERROR unexpected end of macro invocation
- barstar!(a?); //~ ERROR unexpected end of macro invocation
+ barstar!(); //~ ERROR unexpected end of macro invocation
+ barplus!(a?); //~ ERROR no rules expected the token `?`
+ barplus!(a); //~ ERROR unexpected end of macro invocation
+ barstar!(a?); //~ ERROR no rules expected the token `?`
+ barstar!(a); //~ ERROR unexpected end of macro invocation
+ barplus!(+); // ok
+ barstar!(*); // ok
+ barplus!(a); // ok
+ barstar!(a*); // ok
}