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

Commit

Permalink
feat(rustup): Version bump aster and syntex
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Nov 9, 2015
1 parent 282dad7 commit df3a4ab
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.
4 changes: 2 additions & 2 deletions quasi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quasi"
version = "0.3.6"
version = "0.3.7"
authors = ["Erick Tryzelaar <[email protected]>"]
license = "MIT/Apache-2.0"
description = "A quasi-quoting macro system"
Expand All @@ -10,4 +10,4 @@ repository = "https://github.com/erickt/rust-quasi"
with-syntex = ["syntex_syntax"]

[dependencies]
syntex_syntax = { version = "^0.19.0", optional = true }
syntex_syntax = { version = "^0.20.0", optional = true }
38 changes: 19 additions & 19 deletions quasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,49 +73,49 @@ impl<T: ToTokens> ToTokens for Option<T> {

impl ToTokens for ast::Ident {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(DUMMY_SP, token::Ident(*self, token::Plain))]
vec![ast::TokenTree::Token(DUMMY_SP, token::Ident(*self, token::Plain))]
}
}

impl ToTokens for ast::Path {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(DUMMY_SP, token::Interpolated(token::NtPath(Box::new(self.clone()))))]
vec![ast::TokenTree::Token(DUMMY_SP, token::Interpolated(token::NtPath(Box::new(self.clone()))))]
}
}

impl ToTokens for ast::Ty {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtTy(P(self.clone()))))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtTy(P(self.clone()))))]
}
}

impl ToTokens for P<ast::Ty> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtTy(self.clone())))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtTy(self.clone())))]
}
}

impl ToTokens for P<ast::Block> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtBlock(self.clone())))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtBlock(self.clone())))]
}
}

impl ToTokens for P<ast::Item> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtItem(self.clone())))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtItem(self.clone())))]
}
}

impl ToTokens for P<ast::ImplItem> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtImplItem(self.clone())))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtImplItem(self.clone())))]
}
}

impl ToTokens for P<ast::TraitItem> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtTraitItem(self.clone())))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtTraitItem(self.clone())))]
}
}

Expand All @@ -140,12 +140,12 @@ impl ToTokens for ast::WhereClause {
impl ToTokens for P<ast::Stmt> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
let mut tts = vec![
ast::TtToken(self.span, token::Interpolated(token::NtStmt(self.clone())))
ast::TokenTree::Token(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.push(ast::TokenTree::Token(self.span, token::Semi));
}

tts
Expand All @@ -154,19 +154,19 @@ impl ToTokens for P<ast::Stmt> {

impl ToTokens for P<ast::Expr> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtExpr(self.clone())))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtExpr(self.clone())))]
}
}

impl ToTokens for P<ast::Pat> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(self.span, token::Interpolated(token::NtPat(self.clone())))]
vec![ast::TokenTree::Token(self.span, token::Interpolated(token::NtPat(self.clone())))]
}
}

impl ToTokens for ast::Arm {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(DUMMY_SP, token::Interpolated(token::NtArm(self.clone())))]
vec![ast::TokenTree::Token(DUMMY_SP, token::Interpolated(token::NtArm(self.clone())))]
}
}

Expand All @@ -187,24 +187,24 @@ macro_rules! impl_to_tokens_slice {
};
}

impl_to_tokens_slice! { ast::Ty, [ast::TtToken(DUMMY_SP, token::Comma)] }
impl_to_tokens_slice! { ast::Ty, [ast::TokenTree::Token(DUMMY_SP, token::Comma)] }
impl_to_tokens_slice! { P<ast::Item>, [] }

impl ToTokens for P<ast::MetaItem> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtToken(DUMMY_SP, token::Interpolated(token::NtMeta(self.clone())))]
vec![ast::TokenTree::Token(DUMMY_SP, token::Interpolated(token::NtMeta(self.clone())))]
}
}

impl ToTokens for ast::Attribute {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let mut r = vec![];
// FIXME: The spans could be better
r.push(ast::TtToken(self.span, token::Pound));
r.push(ast::TokenTree::Token(self.span, token::Pound));
if self.node.style == ast::AttrStyle::Inner {
r.push(ast::TtToken(self.span, token::Not));
r.push(ast::TokenTree::Token(self.span, token::Not));
}
r.push(ast::TtDelimited(self.span, Rc::new(ast::Delimited {
r.push(ast::TokenTree::Delimited(self.span, Rc::new(ast::Delimited {
delim: token::Bracket,
open_span: self.span,
tts: self.node.value.to_tokens(cx),
Expand All @@ -224,7 +224,7 @@ impl ToTokens for str {

impl ToTokens for () {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec![ast::TtDelimited(DUMMY_SP, Rc::new(ast::Delimited {
vec![ast::TokenTree::Delimited(DUMMY_SP, Rc::new(ast::Delimited {
delim: token::Paren,
open_span: DUMMY_SP,
tts: vec![],
Expand Down
4 changes: 2 additions & 2 deletions quasi_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ default = ["with-syntex"]
with-syntex = ["syntex", "syntex_syntax", "aster/with-syntex"]

[dependencies]
aster = { version = "^0.6.0", default-features = false }
aster = { version = "^0.7.0", default-features = false }
syntex = { version = "^0.17.0", optional = true }
syntex_syntax = { version = "^0.19.0", optional = true }
syntex_syntax = { version = "^0.20.0", optional = true }
37 changes: 22 additions & 15 deletions quasi_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn expand_quote_ty<'cx>(
let expanded = expand_parse_call(
cx,
sp,
&["syntax", "parse", "parser", "Parser", "parse_ty"],
&["syntax", "parse", "parser", "Parser", "parse_ty_panic"],
vec!(),
tts);
base::MacEager::expr(expanded)
Expand All @@ -71,7 +71,7 @@ fn expand_quote_expr<'cx>(
let expanded = expand_parse_call(
cx,
sp,
&["syntax", "parse", "parser", "Parser", "parse_expr"],
&["syntax", "parse", "parser", "Parser", "parse_expr_panic"],
Vec::new(),
tts);
base::MacEager::expr(expanded)
Expand All @@ -85,7 +85,7 @@ fn expand_quote_stmt<'cx>(
let expanded = expand_parse_call(
cx,
sp,
&["syntax", "parse", "parser", "Parser", "parse_stmt"],
&["syntax", "parse", "parser", "Parser", "parse_stmt_panic"],
vec!(),
tts);
base::MacEager::expr(expanded)
Expand All @@ -101,7 +101,7 @@ fn expand_quote_attr<'cx>(
let expanded = expand_parse_call(
cx,
sp,
&["syntax", "parse", "attr", "ParserAttr", "parse_attribute"],
&["syntax", "parse", "parser", "Parser", "parse_attribute_panic"],
vec![builder.expr().bool(true)],
tts);

Expand Down Expand Up @@ -135,7 +135,7 @@ fn expand_quote_pat<'cx>(
let expanded = expand_parse_call(
cx,
sp,
&["syntax", "parse", "parser", "Parser", "parse_pat"],
&["syntax", "parse", "parser", "Parser", "parse_pat_panic"],
vec!(),
tts);
base::MacEager::expr(expanded)
Expand All @@ -149,7 +149,7 @@ fn expand_quote_arm<'cx>(
let expanded = expand_parse_call(
cx,
sp,
&["syntax", "parse", "parser", "Parser", "parse_arm"],
&["syntax", "parse", "parser", "Parser", "parse_arm_panic"],
vec!(),
tts);
base::MacEager::expr(expanded)
Expand Down Expand Up @@ -177,7 +177,7 @@ fn expand_quote_item<'cx>(
let expanded = expand_parse_call(
cx,
sp,
&["syntax", "parse", "parser", "Parser", "parse_item"],
&["syntax", "parse", "parser", "Parser", "parse_item_panic"],
vec!(),
tts);
base::MacEager::expr(expanded)
Expand Down Expand Up @@ -231,6 +231,13 @@ fn mk_ast_path(builder: &aster::AstBuilder, name: &str) -> P<ast::Expr> {
.build()
}

fn mk_tt_path(builder: &aster::AstBuilder, name: &str) -> P<ast::Expr> {
builder.expr().path()
.global()
.ids(&["syntax", "ast", "TokenTree", name])
.build()
}

fn mk_token_path(builder: &aster::AstBuilder, name: &str) -> P<ast::Expr> {
builder.expr().path()
.global()
Expand Down Expand Up @@ -452,7 +459,7 @@ fn statements_mk_tt(tt: &ast::TokenTree, matcher: bool) -> Vec<P<ast::Stmt>> {
let builder = aster::AstBuilder::new();

match *tt {
ast::TtToken(sp, SubstNt(ident, _)) => {
ast::TokenTree::Token(sp, SubstNt(ident, _)) => {
// tt.extend($ident.to_tokens(ext_cx).into_iter())

let builder = builder.clone().span(sp);
Expand All @@ -479,18 +486,18 @@ fn statements_mk_tt(tt: &ast::TokenTree, matcher: bool) -> Vec<P<ast::Stmt>> {

vec![builder.stmt().build_expr(e_push)]
}
ref tt @ ast::TtToken(_, MatchNt(..)) if !matcher => {
ref tt @ ast::TokenTree::Token(_, MatchNt(..)) if !matcher => {
let mut seq = vec![];
for i in 0..tt.len() {
seq.push(tt.get_tt(i));
}
statements_mk_tts(&seq[..], matcher)
}
ast::TtToken(sp, ref tok) => {
ast::TokenTree::Token(sp, ref tok) => {
let builder = builder.clone().span(sp);

let e_tok = builder.expr().call()
.build(mk_ast_path(&builder, "TtToken"))
.build(mk_tt_path(&builder, "Token"))
.arg().id("_sp")
.with_arg(expr_mk_token(&builder, tok))
.build();
Expand All @@ -502,16 +509,16 @@ fn statements_mk_tt(tt: &ast::TokenTree, matcher: bool) -> Vec<P<ast::Stmt>> {

vec![builder.stmt().build_expr(e_push)]
},
ast::TtDelimited(_, ref delimed) => {
ast::TokenTree::Delimited(_, ref delimed) => {
statements_mk_tt(&delimed.open_tt(), matcher).into_iter()
.chain(delimed.tts.iter()
.flat_map(|tt| statements_mk_tt(tt, matcher).into_iter()))
.chain(statements_mk_tt(&delimed.close_tt(), matcher).into_iter())
.collect()
},
ast::TtSequence(sp, ref seq) => {
ast::TokenTree::Sequence(sp, ref seq) => {
if !matcher {
panic!("TtSequence in quote!");
panic!("TokenTree::Sequence in quote!");
}

let builder = builder.clone().span(sp);
Expand Down Expand Up @@ -551,7 +558,7 @@ fn statements_mk_tt(tt: &ast::TokenTree, matcher: bool) -> Vec<P<ast::Stmt>> {
.build(e_seq_struct);

let e_tok = builder.expr().call()
.build(mk_ast_path(&builder, "TtSequence"))
.build(mk_tt_path(&builder, "Sequence"))
.arg().build(e_sp)
.arg().build(e_rc_new)
.build();
Expand Down
4 changes: 2 additions & 2 deletions quasi_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quasi_macros"
version = "0.3.6"
version = "0.3.7"
authors = ["Erick Tryzelaar <[email protected]>"]
license = "MIT/Apache-2.0"
description = "A quasi-quoting macro system"
Expand All @@ -14,5 +14,5 @@ plugin = true
quasi_codegen = { version = "*", path = "../quasi_codegen", default-features = false }

[dev-dependencies]
aster = "^0.6.0"
aster = "^0.7.0"
quasi = { version = "*", path = "../quasi" }
4 changes: 2 additions & 2 deletions quasi_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ quasi_codegen = { version = "*", path = "../quasi_codegen" }
syntex = { version = "^0.17.0" }

[dev-dependencies]
aster = { version = "^0.6.0", features = ["with-syntex"] }
aster = { version = "^0.7.0", features = ["with-syntex"] }
quasi = { version = "*", path = "../quasi", features = ["with-syntex"] }
syntex = { version = "^0.17.0" }
syntex_syntax = { version = "^0.19.0" }
syntex_syntax = { version = "^0.20.0" }

0 comments on commit df3a4ab

Please sign in to comment.