Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Some statements require a trailing semicolon token
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed May 2, 2015
1 parent a53b893 commit 204b3d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ extern crate syntax;
use syntax::ast;
use syntax::codemap::Spanned;
use syntax::ext::base::ExtCtxt;
use syntax::parse::token;
use syntax::parse;
use syntax::parse::{self, classify, token};
use syntax::ptr::P;
use std::rc::Rc;

Expand Down Expand Up @@ -133,7 +132,16 @@ impl ToTokens for ast::WhereClause {

impl ToTokens for P<ast::Stmt> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtStmt(self.clone())))]
let mut tts = vec![
ast::TtToken(self.span, token::Interpolated(token::NtStmt(self.clone())))
];

// Some statements require a trailing semicolon.
if classify::stmt_ends_with_semi(&self.node) {
tts.push(ast::TtToken(self.span, token::Semi));
}

tts
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,18 @@ fn test_quote_with_generics_and_where_clause() {
"impl <T: Clone> Clone for Foo where T: Clone { }"
);
}

#[test]
fn test_stmt_semicolons() {
let sess = parse::new_parse_sess();
let cx = make_ext_ctxt(&sess);

let stmts = vec![
quote_stmt!(&cx, "let x = 1;"),
quote_stmt!(&cx, "let x = 2;"),
];

quote_block!(&cx, {
$stmts
}).ok().unwrap();
}

0 comments on commit 204b3d5

Please sign in to comment.