2014-02-07 13:08:32 -06:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-10 19:32:48 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-06-12 23:34:32 -05:00
|
|
|
// ignore-android
|
|
|
|
// ignore-pretty: does not work well with `--test`
|
|
|
|
|
2014-04-03 19:55:06 -05:00
|
|
|
#![feature(quote)]
|
2013-10-25 19:04:37 -05:00
|
|
|
|
2014-02-14 12:10:06 -06:00
|
|
|
extern crate syntax;
|
2012-11-16 16:50:35 -06:00
|
|
|
|
2013-05-17 06:27:17 -05:00
|
|
|
use syntax::ext::base::ExtCtxt;
|
2014-06-11 21:33:52 -05:00
|
|
|
use std::gc::Gc;
|
2012-11-16 16:50:35 -06:00
|
|
|
|
2013-12-27 18:17:36 -06:00
|
|
|
fn syntax_extension(cx: &ExtCtxt) {
|
2014-06-12 18:36:26 -05:00
|
|
|
let e_toks : Vec<syntax::ast::TokenTree> = quote_tokens!(cx, 1 + 2);
|
|
|
|
let p_toks : Vec<syntax::ast::TokenTree> = quote_tokens!(cx, (x, 1 .. 4, *));
|
2012-11-16 16:50:35 -06:00
|
|
|
|
2014-06-11 21:33:52 -05:00
|
|
|
let a: Gc<syntax::ast::Expr> = quote_expr!(cx, 1 + 2);
|
|
|
|
let _b: Option<Gc<syntax::ast::Item>> = quote_item!(cx, static foo : int = $e_toks; );
|
|
|
|
let _c: Gc<syntax::ast::Pat> = quote_pat!(cx, (x, 1 .. 4, *) );
|
|
|
|
let _d: Gc<syntax::ast::Stmt> = quote_stmt!(cx, let x = $a; );
|
|
|
|
let _e: Gc<syntax::ast::Expr> = quote_expr!(cx, match foo { $p_toks => 10 } );
|
2014-05-01 08:39:00 -05:00
|
|
|
|
2014-06-11 21:33:52 -05:00
|
|
|
let _f: Gc<syntax::ast::Expr> = quote_expr!(cx, ());
|
|
|
|
let _g: Gc<syntax::ast::Expr> = quote_expr!(cx, true);
|
|
|
|
let _h: Gc<syntax::ast::Expr> = quote_expr!(cx, 'a');
|
2014-06-12 18:40:10 -05:00
|
|
|
|
2014-06-11 21:33:52 -05:00
|
|
|
let i: Option<Gc<syntax::ast::Item>> = quote_item!(cx, #[deriving(Eq)] struct Foo; );
|
2014-06-12 18:40:10 -05:00
|
|
|
assert!(i.is_some());
|
2012-11-16 16:50:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|