]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/quote-tokens.rs
Imported Upstream version 1.8.0+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / quote-tokens.rs
1 // Copyright 2012-2014 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 // ignore-cross-compile
12 // ignore-pretty: does not work well with `--test`
13
14 #![feature(quote, rustc_private)]
15
16 extern crate syntax;
17
18 use syntax::ext::base::ExtCtxt;
19 use syntax::ptr::P;
20 use syntax::parse::PResult;
21
22 fn syntax_extension(cx: &ExtCtxt) {
23 let e_toks : Vec<syntax::ast::TokenTree> = quote_tokens!(cx, 1 + 2);
24 let p_toks : Vec<syntax::ast::TokenTree> = quote_tokens!(cx, (x, 1 .. 4, *));
25
26 let a: P<syntax::ast::Expr> = quote_expr!(cx, 1 + 2);
27 let _b: Option<P<syntax::ast::Item>> = quote_item!(cx, static foo : isize = $e_toks; );
28 let _c: P<syntax::ast::Pat> = quote_pat!(cx, (x, 1 .. 4, *) );
29 let _d: Option<syntax::ast::Stmt> = quote_stmt!(cx, let x = $a; );
30 let _d: syntax::ast::Arm = quote_arm!(cx, (ref x, ref y) = (x, y) );
31 let _e: P<syntax::ast::Expr> = quote_expr!(cx, match foo { $p_toks => 10 } );
32
33 let _f: P<syntax::ast::Expr> = quote_expr!(cx, ());
34 let _g: P<syntax::ast::Expr> = quote_expr!(cx, true);
35 let _h: P<syntax::ast::Expr> = quote_expr!(cx, 'a');
36
37 let i: Option<P<syntax::ast::Item>> = quote_item!(cx, #[derive(Eq)] struct Foo; );
38 assert!(i.is_some());
39
40 let _l: P<syntax::ast::Ty> = quote_ty!(cx, &isize);
41
42 let _m: Vec<syntax::ast::TokenTree> = quote_matcher!(cx, $($foo:tt,)* bar);
43 let _n: syntax::ast::Attribute = quote_attr!(cx, #![cfg(foo, bar = "baz")]);
44
45 let _o: Option<P<syntax::ast::Item>> = quote_item!(cx, fn foo<T: ?Sized>() {});
46
47 let stmts = vec![
48 quote_stmt!(cx, let x = 1;).unwrap(),
49 quote_stmt!(cx, let y = 2;).unwrap(),
50 ];
51 let expr: P<syntax::ast::Expr> = quote_expr!(cx, x + y);
52 }
53
54 fn main() {
55 }