]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
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 | ||
d9579d0f | 11 | // ignore-cross-compile |
c34b1796 | 12 | #![feature(quote, rustc_private)] |
1a4d82fc JJ |
13 | |
14 | extern crate syntax; | |
223e47cc | 15 | |
970d7e83 | 16 | use syntax::ext::base::ExtCtxt; |
1a4d82fc | 17 | use syntax::ptr::P; |
9346a6ac | 18 | use syntax::parse::PResult; |
1a4d82fc JJ |
19 | |
20 | fn syntax_extension(cx: &ExtCtxt) { | |
3157f602 XL |
21 | let e_toks : Vec<syntax::tokenstream::TokenTree> = quote_tokens!(cx, 1 + 2); |
22 | let p_toks : Vec<syntax::tokenstream::TokenTree> = quote_tokens!(cx, (x, 1 .. 4, *)); | |
1a4d82fc JJ |
23 | |
24 | let a: P<syntax::ast::Expr> = quote_expr!(cx, 1 + 2); | |
c34b1796 | 25 | let _b: Option<P<syntax::ast::Item>> = quote_item!(cx, static foo : isize = $e_toks; ); |
1a4d82fc | 26 | let _c: P<syntax::ast::Pat> = quote_pat!(cx, (x, 1 .. 4, *) ); |
7453a54e | 27 | let _d: Option<syntax::ast::Stmt> = quote_stmt!(cx, let x = $a; ); |
1a4d82fc JJ |
28 | let _d: syntax::ast::Arm = quote_arm!(cx, (ref x, ref y) = (x, y) ); |
29 | let _e: P<syntax::ast::Expr> = quote_expr!(cx, match foo { $p_toks => 10 } ); | |
30 | ||
31 | let _f: P<syntax::ast::Expr> = quote_expr!(cx, ()); | |
32 | let _g: P<syntax::ast::Expr> = quote_expr!(cx, true); | |
33 | let _h: P<syntax::ast::Expr> = quote_expr!(cx, 'a'); | |
34 | ||
35 | let i: Option<P<syntax::ast::Item>> = quote_item!(cx, #[derive(Eq)] struct Foo; ); | |
36 | assert!(i.is_some()); | |
223e47cc | 37 | |
c34b1796 | 38 | let _l: P<syntax::ast::Ty> = quote_ty!(cx, &isize); |
223e47cc | 39 | |
c34b1796 AL |
40 | let _n: syntax::ast::Attribute = quote_attr!(cx, #![cfg(foo, bar = "baz")]); |
41 | ||
42 | let _o: Option<P<syntax::ast::Item>> = quote_item!(cx, fn foo<T: ?Sized>() {}); | |
d9579d0f AL |
43 | |
44 | let stmts = vec![ | |
45 | quote_stmt!(cx, let x = 1;).unwrap(), | |
46 | quote_stmt!(cx, let y = 2;).unwrap(), | |
47 | ]; | |
48 | let expr: P<syntax::ast::Expr> = quote_expr!(cx, x + y); | |
223e47cc LB |
49 | } |
50 | ||
51 | fn main() { | |
52 | } |