]> git.lizzy.rs Git - rust.git/blob - src/test/ui/macros/macro-at-most-once-rep-ambig.rs
No separator for `?`. No `?` as a separator.
[rust.git] / src / test / ui / macros / macro-at-most-once-rep-ambig.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Tests the behavior of various Kleene operators in macros with respect to `?` terminals. In
12 // particular, `?` in the position of a separator and of a Kleene operator is tested.
13
14 #![feature(macro_at_most_once_rep)]
15
16 // should match `` and `a`
17 macro_rules! foo {
18     ($(a)?) => {}
19 }
20
21 macro_rules! baz {
22     ($(a),?) => {} //~ ERROR `?` macro repetition does not allow a separator
23 }
24
25 // should match `+` and `a+`
26 macro_rules! barplus {
27     ($(a)?+) => {}
28 }
29
30 // should match `*` and `a*`
31 macro_rules! barstar {
32     ($(a)?*) => {}
33 }
34
35 pub fn main() {
36     foo!(a?a?a); //~ ERROR no rules expected the token `?`
37     foo!(a?a); //~ ERROR no rules expected the token `?`
38     foo!(a?); //~ ERROR no rules expected the token `?`
39     barplus!(); //~ ERROR unexpected end of macro invocation
40     barstar!(); //~ ERROR unexpected end of macro invocation
41     barplus!(a?); //~ ERROR no rules expected the token `?`
42     barplus!(a); //~ ERROR unexpected end of macro invocation
43     barstar!(a?); //~ ERROR no rules expected the token `?`
44     barstar!(a); //~ ERROR unexpected end of macro invocation
45     barplus!(+); // ok
46     barstar!(*); // ok
47     barplus!(a); // ok
48     barstar!(a*); // ok
49 }