syntax: implement ToSource for more things in the quasiquoter.
The last few primitive types were missing.
This commit is contained in:
parent
5c424ba34a
commit
1d43a98dea
2 changed files with 27 additions and 0 deletions
|
|
@ -125,6 +125,26 @@ pub mod rt {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToSource for () {
|
||||
fn to_source(&self) -> ~str {
|
||||
"()".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSource for bool {
|
||||
fn to_source(&self) -> ~str {
|
||||
let lit = dummy_spanned(ast::LitBool(*self));
|
||||
pprust::lit_to_str(&lit)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSource for char {
|
||||
fn to_source(&self) -> ~str {
|
||||
let lit = dummy_spanned(ast::LitChar(*self));
|
||||
pprust::lit_to_str(&lit)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSource for int {
|
||||
fn to_source(&self) -> ~str {
|
||||
let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI));
|
||||
|
|
@ -227,6 +247,9 @@ pub mod rt {
|
|||
impl_to_tokens!(@ast::Expr)
|
||||
impl_to_tokens!(ast::Block)
|
||||
impl_to_tokens_self!(&'a str)
|
||||
impl_to_tokens!(())
|
||||
impl_to_tokens!(char)
|
||||
impl_to_tokens!(bool)
|
||||
impl_to_tokens!(int)
|
||||
impl_to_tokens!(i8)
|
||||
impl_to_tokens!(i16)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ fn syntax_extension(cx: &ExtCtxt) {
|
|||
let _c: @syntax::ast::Pat = quote_pat!(cx, (x, 1 .. 4, *) );
|
||||
let _d: @syntax::ast::Stmt = quote_stmt!(cx, let x = $a; );
|
||||
let _e: @syntax::ast::Expr = quote_expr!(cx, match foo { $p_toks => 10 } );
|
||||
|
||||
let _f: @syntax::ast::Expr = quote_expr!(cx, ());
|
||||
let _g: @syntax::ast::Expr = quote_expr!(cx, true);
|
||||
let _h: @syntax::ast::Expr = quote_expr!(cx, 'a');
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue