This should be clearer, and fits in better with the `TTNonterminal` variant.
Renames:
- `TTTok` -> `TTToken`
- `TTDelim` -> `TTDelimited`
- `TTSeq` -> `TTSequence`
use syntax::codemap::Span;
use syntax::parse::token::{IDENT, get_ident};
-use syntax::ast::{TokenTree, TTTok};
+use syntax::ast::{TokenTree, TTToken};
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacExpr};
use syntax::ext::build::AstBuilder; // trait for expr_uint
use rustc::plugin::Registry;
("I", 1)];
let text = match args {
- [TTTok(_, IDENT(s, _))] => get_ident(s).to_string(),
+ [TTToken(_, IDENT(s, _))] => get_ident(s).to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
return DummyResult::any(sp);
use std::rc::Rc;
use serialize::{Encodable, Decodable, Encoder, Decoder};
+#[cfg(stage0)]
+pub use self::TTToken as TTTok;
+
// FIXME #6993: in librustc, uses of "ident" should be replaced
// by just "Name".
}
impl Delimiter {
- /// Convert the delimiter to a `TTTok`
+ /// Convert the delimiter to a `TTToken`
pub fn to_tt(&self) -> TokenTree {
- TTTok(self.span, self.token.clone())
+ TTToken(self.span, self.token.clone())
}
}
/// If the syntax extension is an MBE macro, it will attempt to match its
/// LHS "matchers" against the provided token tree, and if it finds a
/// match, will transcribe the RHS token tree, splicing in any captured
-/// macro_parser::matched_nonterminals into the TTNonterminals it finds.
+/// `macro_parser::matched_nonterminals` into the `TTNonterminal`s it finds.
///
-/// The RHS of an MBE macro is the only place a TTNonterminal or TTSeq
+/// The RHS of an MBE macro is the only place a `TTNonterminal` or `TTSequence`
/// makes any real sense. You could write them elsewhere but nothing
/// else knows what to do with them, so you'll probably get a syntax
/// error.
#[doc="For macro invocations; parsing is delegated to the macro"]
pub enum TokenTree {
/// A single token
- TTTok(Span, ::parse::token::Token),
+ TTToken(Span, ::parse::token::Token),
/// A delimited sequence of token trees
// FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST.
- TTDelim(Span, Delimiter, Rc<Vec<TokenTree>>, Delimiter),
+ TTDelimited(Span, Delimiter, Rc<Vec<TokenTree>>, Delimiter),
// These only make sense for right-hand-sides of MBE macros:
- /// A kleene-style repetition sequence with a span, a TTForest,
+ /// A kleene-style repetition sequence with a span, a `TTForest`,
/// an optional separator, and a boolean where true indicates
/// zero or more (..), and false indicates one or more (+).
// FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST.
- TTSeq(Span, Rc<Vec<TokenTree>>, Option<::parse::token::Token>, bool),
+ TTSequence(Span, Rc<Vec<TokenTree>>, Option<::parse::token::Token>, bool),
/// A syntactic variable that will be filled in by macro expansion.
TTNonterminal(Span, Ident)
/// Returns the `Span` corresponding to this token tree.
pub fn get_span(&self) -> Span {
match *self {
- TTTok(span, _) => span,
- TTDelim(span, _, _, _) => span,
- TTSeq(span, _, _, _) => span,
- TTNonterminal(span, _) => span,
+ TTToken(span, _) => span,
+ TTDelimited(span, _, _, _) => span,
+ TTSequence(span, _, _, _) => span,
+ TTNonterminal(span, _) => span,
}
}
}
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let code = match token_tree {
- [ast::TTTok(_, token::IDENT(code, _))] => code,
+ [ast::TTToken(_, token::IDENT(code, _))] => code,
_ => unreachable!()
};
with_registered_diagnostics(|diagnostics| {
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let (code, description) = match token_tree {
- [ast::TTTok(_, token::IDENT(ref code, _))] => {
+ [ast::TTToken(_, token::IDENT(ref code, _))] => {
(code, None)
},
- [ast::TTTok(_, token::IDENT(ref code, _)),
- ast::TTTok(_, token::COMMA),
- ast::TTTok(_, token::LIT_STR_RAW(description, _))] => {
+ [ast::TTToken(_, token::IDENT(ref code, _)),
+ ast::TTToken(_, token::COMMA),
+ ast::TTToken(_, token::LIT_STR_RAW(description, _))] => {
(code, Some(description))
}
_ => unreachable!()
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let name = match token_tree {
- [ast::TTTok(_, token::IDENT(ref name, _))] => name,
+ [ast::TTToken(_, token::IDENT(ref name, _))] => name,
_ => unreachable!()
};
cx.span_err(sp, format!("{} takes 1 argument.", name).as_slice());
} else {
match tts[0] {
- ast::TTTok(_, token::LIT_STR(ident)) => return Some(parse::str_lit(ident.as_str())),
- ast::TTTok(_, token::LIT_STR_RAW(ident, _)) => {
+ ast::TTToken(_, token::LIT_STR(ident)) => return Some(parse::str_lit(ident.as_str())),
+ ast::TTToken(_, token::LIT_STR_RAW(ident, _)) => {
return Some(parse::raw_str_lit(ident.as_str()))
}
_ => {
for (i, e) in tts.iter().enumerate() {
if i & 1 == 1 {
match *e {
- ast::TTTok(_, token::COMMA) => (),
+ ast::TTToken(_, token::COMMA) => (),
_ => {
cx.span_err(sp, "concat_idents! expecting comma.");
return DummyResult::expr(sp);
}
} else {
match *e {
- ast::TTTok(_, token::IDENT(ident,_)) => {
+ ast::TTToken(_, token::IDENT(ident,_)) => {
res_str.push_str(token::get_ident(ident).get())
}
_ => {
fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {
match *tt {
- ast::TTTok(sp, ref tok) => {
+ ast::TTToken(sp, ref tok) => {
let e_sp = cx.expr_ident(sp, id_ext("_sp"));
let e_tok = cx.expr_call(sp,
- mk_ast_path(cx, sp, "TTTok"),
+ mk_ast_path(cx, sp, "TTToken"),
vec!(e_sp, mk_token(cx, sp, tok)));
let e_push =
cx.expr_method_call(sp,
vec!(e_tok));
vec!(cx.stmt_expr(e_push))
},
- ast::TTDelim(sp, ref open, ref tts, ref close) => {
+ ast::TTDelimited(sp, ref open, ref tts, ref close) => {
let mut stmts = vec![];
stmts.extend(mk_tt(cx, sp, &open.to_tt()).into_iter());
stmts.extend(tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter()));
stmts.extend(mk_tt(cx, sp, &close.to_tt()).into_iter());
stmts
},
- ast::TTSeq(..) => fail!("TTSeq in quote!"),
+ ast::TTSequence(..) => fail!("TTSequence in quote!"),
ast::TTNonterminal(sp, ident) => {
// tt.extend($ident.to_tokens(ext_cx).into_iter())
tt: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
match tt {
- [ast::TTTok(_, ref tok)] if is_keyword(keywords::True, tok) => {
+ [ast::TTToken(_, ref tok)] if is_keyword(keywords::True, tok) => {
cx.set_trace_macros(true);
}
- [ast::TTTok(_, ref tok)] if is_keyword(keywords::False, tok) => {
+ [ast::TTToken(_, ref tok)] if is_keyword(keywords::False, tok) => {
cx.set_trace_macros(false);
}
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use ast::{Ident, Matcher_, Matcher, MatchTok, MatchNonterminal, MatchSeq, TTDelim};
+use ast::{Ident, Matcher_, Matcher, MatchTok, MatchNonterminal, MatchSeq, TTDelimited};
use ast;
use codemap::{Span, Spanned, DUMMY_SP};
use ext::base::{ExtCtxt, MacResult, MacroDef};
MatchedNonterminal(NtTT(ref tt)) => {
match **tt {
// ignore delimiters
- TTDelim(_, _, ref tts, _) => (**tts).clone(),
+ TTDelimited(_, _, ref tts, _) => (**tts).clone(),
_ => cx.span_fatal(sp, "macro rhs must be delimited"),
}
},
// except according to those terms.
use ast;
-use ast::{TokenTree, TTDelim, TTTok, TTSeq, TTNonterminal, Ident};
+use ast::{TokenTree, TTDelimited, TTToken, TTSequence, TTNonterminal, Ident};
use codemap::{Span, DUMMY_SP};
use diagnostic::SpanHandler;
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
}
/// This can do Macro-By-Example transcription. On the other hand, if
-/// `src` contains no `TTSeq`s and `TTNonterminal`s, `interp` can (and
+/// `src` contains no `TTSequence`s and `TTNonterminal`s, `interp` can (and
/// should) be none.
pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler,
interp: Option<HashMap<Ident, Rc<NamedMatch>>>,
match *t {
// The opening and closing delimiters are both tokens, so they are
// treated as `LisUnconstrained`.
- TTDelim(_, _, ref tts, _) | TTSeq(_, ref tts, _, _) => {
+ TTDelimited(_, _, ref tts, _) | TTSequence(_, ref tts, _, _) => {
tts.iter().fold(LisUnconstrained, |size, tt| {
size + lockstep_iter_size(tt, r)
})
},
- TTTok(..) => LisUnconstrained,
+ TTToken(..) => LisUnconstrained,
TTNonterminal(_, name) => match *lookup_cur_matched(r, name) {
MatchedNonterminal(_) => LisUnconstrained,
MatchedSeq(ref ads, _) => LisConstraint(ads.len(), name)
}
}
}
- loop { /* because it's easiest, this handles `TTDelim` not starting
- with a `TTTok`, even though it won't happen */
+ loop { /* because it's easiest, this handles `TTDelimited` not starting
+ with a `TTToken`, even though it won't happen */
let t = {
let frame = r.stack.last().unwrap();
// FIXME(pcwalton): Bad copy.
(*frame.forest)[frame.idx].clone()
};
match t {
- TTDelim(_, open, delimed_tts, close) => {
+ TTDelimited(_, open, delimed_tts, close) => {
let mut tts = vec![];
tts.push(open.to_tt());
tts.extend(delimed_tts.iter().map(|x| (*x).clone()));
});
// if this could be 0-length, we'd need to potentially recur here
}
- TTTok(sp, tok) => {
+ TTToken(sp, tok) => {
r.cur_span = sp;
r.cur_tok = tok;
r.stack.last_mut().unwrap().idx += 1;
return ret_val;
}
- TTSeq(sp, tts, sep, zerok) => {
+ TTSequence(sp, tts, sep, zerok) => {
// FIXME(pcwalton): Bad copy.
- match lockstep_iter_size(&TTSeq(sp, tts.clone(), sep.clone(), zerok), r) {
+ match lockstep_iter_size(&TTSequence(sp, tts.clone(), sep.clone(), zerok), r) {
LisUnconstrained => {
r.sp_diag.span_fatal(
sp.clone(), /* blame macro writer */
pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
match *tt {
- TTTok(span, ref tok) =>
- TTTok(span, fld.fold_token(tok.clone())),
- TTDelim(span, ref open, ref tts, ref close) =>
- TTDelim(span,
- Delimiter {
- span: open.span,
- token: fld.fold_token(open.token.clone())
- },
- Rc::new(fld.fold_tts(tts.as_slice())),
- Delimiter {
- span: close.span,
- token: fld.fold_token(close.token.clone())
- }),
- TTSeq(span, ref pattern, ref sep, is_optional) =>
- TTSeq(span,
- Rc::new(fld.fold_tts(pattern.as_slice())),
- sep.clone().map(|tok| fld.fold_token(tok)),
- is_optional),
+ TTToken(span, ref tok) =>
+ TTToken(span, fld.fold_token(tok.clone())),
+ TTDelimited(span, ref open, ref tts, ref close) =>
+ TTDelimited(span,
+ Delimiter {
+ span: open.span,
+ token: fld.fold_token(open.token.clone())
+ },
+ Rc::new(fld.fold_tts(tts.as_slice())),
+ Delimiter {
+ span: close.span,
+ token: fld.fold_token(close.token.clone())
+ }),
+ TTSequence(span, ref pattern, ref sep, is_optional) =>
+ TTSequence(span,
+ Rc::new(fld.fold_tts(pattern.as_slice())),
+ sep.clone().map(|tok| fld.fold_token(tok)),
+ is_optional),
TTNonterminal(sp,ref ident) =>
TTNonterminal(sp,fld.fold_ident(*ident))
}
let tts = string_to_tts("macro_rules! zip (($a)=>($a))".to_string());
let tts: &[ast::TokenTree] = tts.as_slice();
match tts {
- [ast::TTTok(_, _),
- ast::TTTok(_, token::NOT),
- ast::TTTok(_, _),
- ast::TTDelim(_, ast::TTTok(_, token::LPAREN),
+ [ast::TTToken(_, _),
+ ast::TTToken(_, token::NOT),
+ ast::TTToken(_, _),
+ ast::TTDelimited(_, ast::TTToken(_, token::LPAREN),
ref delim_elts,
- ast::TTTok(_, token::RPAREN))] => {
+ ast::TTToken(_, token::RPAREN))] => {
let delim_elts: &[ast::TokenTree] = delim_elts.as_slice();
match delim_elts {
- [ast::TTDelim(_, ast::TTTok(_, token::LPAREN),
+ [ast::TTDelimited(_, ast::TTToken(_, token::LPAREN),
ref first_set,
- ast::TTTok(_, token::RPAREN)),
- ast::TTTok(_, token::FAT_ARROW),
- ast::TTDelim(_, ast::TTTok(_, token::LPAREN),
+ ast::TTToken(_, token::RPAREN)),
+ ast::TTToken(_, token::FAT_ARROW),
+ ast::TTDelimited(_, ast::TTToken(_, token::LPAREN),
ref second_set,
- ast::TTTok(_, token::RPAREN))] => {
+ ast::TTToken(_, token::RPAREN))] => {
let first_set: &[ast::TokenTree] =
first_set.as_slice();
match first_set {
- [ast::TTTok(_, token::DOLLAR), ast::TTTok(_, _)] => {
+ [ast::TTToken(_, token::DOLLAR), ast::TTToken(_, _)] => {
let second_set: &[ast::TokenTree] =
second_set.as_slice();
match second_set {
- [ast::TTTok(_, token::DOLLAR), ast::TTTok(_, _)] => {
+ [ast::TTToken(_, token::DOLLAR), ast::TTToken(_, _)] => {
assert_eq!("correct","correct")
}
_ => assert_eq!("wrong 4","correct")
assert_eq!(json::encode(&tts),
"[\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
{\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
{\
]\
},\
{\
- \"variant\":\"TTDelim\",\
+ \"variant\":\"TTDelimited\",\
\"fields\":[\
[\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
\"LPAREN\"\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
{\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
\"COLON\"\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
{\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
\"RPAREN\"\
]\
},\
{\
- \"variant\":\"TTDelim\",\
+ \"variant\":\"TTDelimited\",\
\"fields\":[\
[\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
\"LBRACE\"\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
{\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
\"SEMI\"\
]\
},\
{\
- \"variant\":\"TTTok\",\
+ \"variant\":\"TTToken\",\
\"fields\":[\
null,\
\"RBRACE\"\
use ast::{StructVariantKind, BiSub};
use ast::StrStyle;
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
-use ast::{Delimiter, TokenTree, TraitItem, TraitRef, TTDelim, TTSeq, TTTok};
+use ast::{Delimiter, TokenTree, TraitItem, TraitRef, TTDelimited, TTSequence, TTToken};
use ast::{TTNonterminal, TupleVariantKind, Ty, Ty_, TyBot};
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
use ast::{TyTypeof, TyInfer, TypeMethod};
/// parse a single token tree from the input.
pub fn parse_token_tree(&mut self) -> TokenTree {
// FIXME #6994: currently, this is too eager. It
- // parses token trees but also identifies TTSeq's
+ // parses token trees but also identifies TTSequence's
// and TTNonterminal's; it's too early to know yet
// whether something will be a nonterminal or a seq
// yet.
let seq = match seq {
Spanned { node, .. } => node,
};
- TTSeq(mk_sp(sp.lo, p.span.hi), Rc::new(seq), s, z)
+ TTSequence(mk_sp(sp.lo, p.span.hi), Rc::new(seq), s, z)
} else {
TTNonterminal(sp, p.parse_ident())
}
}
_ => {
- TTTok(p.span, p.bump_and_get())
+ TTToken(p.span, p.bump_and_get())
}
}
}
// Expand to cover the entire delimited token tree
let span = Span { hi: self.span.hi, ..pre_span };
- TTDelim(span, open, Rc::new(tts), close)
+ TTDelimited(span, open, Rc::new(tts), close)
}
_ => parse_non_delim_tt_tok(self)
}
/// expression arguments as expressions). It can be done! I think.
pub fn print_tt(&mut self, tt: &ast::TokenTree) -> IoResult<()> {
match *tt {
- ast::TTDelim(_, ref open, ref tts, ref close) => {
+ ast::TTDelimited(_, ref open, ref tts, ref close) => {
try!(word(&mut self.s, parse::token::to_string(&open.token).as_slice()));
try!(space(&mut self.s));
try!(self.print_tts(tts.as_slice()));
try!(space(&mut self.s));
word(&mut self.s, parse::token::to_string(&close.token).as_slice())
},
- ast::TTTok(_, ref tk) => {
+ ast::TTToken(_, ref tk) => {
try!(word(&mut self.s, parse::token::to_string(tk).as_slice()));
match *tk {
parse::token::DOC_COMMENT(..) => {
_ => Ok(())
}
}
- ast::TTSeq(_, ref tts, ref sep, zerok) => {
+ ast::TTSequence(_, ref tts, ref sep, zerok) => {
try!(word(&mut self.s, "$("));
for tt_elt in (*tts).iter() {
try!(self.print_tt(tt_elt));
use syntax::codemap::Span;
use syntax::parse::token::{IDENT, get_ident};
-use syntax::ast::{TokenTree, TTTok};
+use syntax::ast::{TokenTree, TTToken};
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacExpr};
use syntax::ext::build::AstBuilder; // trait for expr_uint
use rustc::plugin::Registry;
("I", 1)];
let text = match args {
- [TTTok(_, IDENT(s, _))] => get_ident(s).to_string(),
+ [TTToken(_, IDENT(s, _))] => get_ident(s).to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
return DummyResult::any(sp);