Skip to content

Commit

Permalink
Use standard capitalisation for TokenTree variants
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Oct 25, 2014
1 parent 6a50b4d commit dfb4163
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/doc/guide-plugin.md
Expand Up @@ -56,7 +56,7 @@ extern crate rustc;
use syntax::codemap::Span;
use syntax::parse::token::{IDENT, get_ident};
use syntax::ast::{TokenTree, TTToken};
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;
Expand All @@ -71,7 +71,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
("I", 1)];
let text = match args {
[TTToken(_, 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);
Expand Down
26 changes: 13 additions & 13 deletions src/libsyntax/ast.rs
Expand Up @@ -25,7 +25,7 @@ use std::rc::Rc;
use serialize::{Encodable, Decodable, Encoder, Decoder};

#[cfg(stage0)]
pub use self::TTToken as TTTok;
pub use self::TtToken as TTTok;

// FIXME #6993: in librustc, uses of "ident" should be replaced
// by just "Name".
Expand Down Expand Up @@ -603,9 +603,9 @@ pub struct Delimiter {
}

impl Delimiter {
/// Convert the delimiter to a `TTToken`
/// Convert the delimiter to a `TtToken`
pub fn to_tt(&self) -> TokenTree {
TTToken(self.span, self.token.clone())
TtToken(self.span, self.token.clone())
}
}

Expand All @@ -617,41 +617,41 @@ impl Delimiter {
/// 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 `TTNonterminal`s 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 `TTSequence`
/// 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.
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
#[doc="For macro invocations; parsing is delegated to the macro"]
pub enum TokenTree {
/// A single token
TTToken(Span, ::parse::token::Token),
TtToken(Span, ::parse::token::Token),
/// A delimited sequence of token trees
// FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST.
TTDelimited(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`,
/// 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.
TTSequence(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)
TtNonterminal(Span, Ident)
}

impl TokenTree {
/// Returns the `Span` corresponding to this token tree.
pub fn get_span(&self) -> Span {
match *self {
TTToken(span, _) => span,
TTDelimited(span, _, _, _) => span,
TTSequence(span, _, _, _) => span,
TTNonterminal(span, _) => span,
TtToken(span, _) => span,
TtDelimited(span, _, _, _) => span,
TtSequence(span, _, _, _) => span,
TtNonterminal(span, _) => span,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/diagnostics/plugin.rs
Expand Up @@ -50,7 +50,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let code = match token_tree {
[ast::TTToken(_, token::IDENT(code, _))] => code,
[ast::TtToken(_, token::IDENT(code, _))] => code,
_ => unreachable!()
};
with_registered_diagnostics(|diagnostics| {
Expand Down Expand Up @@ -82,12 +82,12 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let (code, description) = match token_tree {
[ast::TTToken(_, token::IDENT(ref code, _))] => {
[ast::TtToken(_, token::IDENT(ref code, _))] => {
(code, None)
},
[ast::TTToken(_, token::IDENT(ref code, _)),
ast::TTToken(_, token::COMMA),
ast::TTToken(_, 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!()
Expand All @@ -110,7 +110,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let name = match token_tree {
[ast::TTToken(_, token::IDENT(ref name, _))] => name,
[ast::TtToken(_, token::IDENT(ref name, _))] => name,
_ => unreachable!()
};

Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/base.rs
Expand Up @@ -684,8 +684,8 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt,
cx.span_err(sp, format!("{} takes 1 argument.", name).as_slice());
} else {
match tts[0] {
ast::TTToken(_, token::LIT_STR(ident)) => return Some(parse::str_lit(ident.as_str())),
ast::TTToken(_, 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()))
}
_ => {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/concat_idents.rs
Expand Up @@ -23,15 +23,15 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]
for (i, e) in tts.iter().enumerate() {
if i & 1 == 1 {
match *e {
ast::TTToken(_, token::COMMA) => (),
ast::TtToken(_, token::COMMA) => (),
_ => {
cx.span_err(sp, "concat_idents! expecting comma.");
return DummyResult::expr(sp);
}
}
} else {
match *e {
ast::TTToken(_, token::IDENT(ident,_)) => {
ast::TtToken(_, token::IDENT(ident,_)) => {
res_str.push_str(token::get_ident(ident).get())
}
_ => {
Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/ext/quote.rs
Expand Up @@ -23,7 +23,7 @@ use ptr::P;
*
* This is registered as a set of expression syntax extension called quote!
* that lifts its argument token-tree to an AST representing the
* construction of the same token tree, with ast::TTNonterminal nodes
* construction of the same token tree, with ast::TtNonterminal nodes
* interpreted as antiquotes (splices).
*
*/
Expand Down Expand Up @@ -639,10 +639,10 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {

fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {
match *tt {
ast::TTToken(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, "TTToken"),
mk_ast_path(cx, sp, "TtToken"),
vec!(e_sp, mk_token(cx, sp, tok)));
let e_push =
cx.expr_method_call(sp,
Expand All @@ -651,14 +651,14 @@ fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {
vec!(e_tok));
vec!(cx.stmt_expr(e_push))
},
ast::TTDelimited(sp, ref open, ref tts, ref close) => {
ast::TtDelimited(sp, ref open, ref tts, ref close) => {
mk_tt(cx, sp, &open.to_tt()).into_iter()
.chain(tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter()))
.chain(mk_tt(cx, sp, &close.to_tt()).into_iter())
.collect()
},
ast::TTSequence(..) => fail!("TTSequence in quote!"),
ast::TTNonterminal(sp, ident) => {
ast::TtSequence(..) => fail!("TtSequence in quote!"),
ast::TtNonterminal(sp, ident) => {
// tt.extend($ident.to_tokens(ext_cx).into_iter())

let e_to_toks =
Expand Down Expand Up @@ -692,7 +692,7 @@ fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])
fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> (P<ast::Expr>, P<ast::Expr>) {
// NB: It appears that the main parser loses its mind if we consider
// $foo as a TTNonterminal during the main parse, so we have to re-parse
// $foo as a TtNonterminal during the main parse, so we have to re-parse
// under quote_depth > 0. This is silly and should go away; the _guess_ is
// it has to do with transition away from supporting old-style macros, so
// try removing it when enough of them are gone.
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/trace_macros.rs
Expand Up @@ -20,10 +20,10 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
tt: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
match tt {
[ast::TTToken(_, ref tok)] if is_keyword(keywords::True, tok) => {
[ast::TtToken(_, ref tok)] if is_keyword(keywords::True, tok) => {
cx.set_trace_macros(true);
}
[ast::TTToken(_, 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`"),
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/tt/macro_rules.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use ast::{Ident, Matcher_, Matcher, MatchTok, MatchNonterminal, MatchSeq, TTDelimited};
use ast::{Ident, Matcher_, Matcher, MatchTok, MatchNonterminal, MatchSeq, TtDelimited};
use ast;
use codemap::{Span, Spanned, DUMMY_SP};
use ext::base::{ExtCtxt, MacResult, MacroDef};
Expand Down Expand Up @@ -172,7 +172,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
MatchedNonterminal(NtTT(ref tt)) => {
match **tt {
// ignore delimiters
TTDelimited(_, _, ref tts, _) => (**tts).clone(),
TtDelimited(_, _, ref tts, _) => (**tts).clone(),
_ => cx.span_fatal(sp, "macro rhs must be delimited"),
}
},
Expand Down
24 changes: 12 additions & 12 deletions src/libsyntax/ext/tt/transcribe.rs
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use ast;
use ast::{TokenTree, TTDelimited, TTToken, TTSequence, 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};
Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct TtReader<'a> {
}

/// This can do Macro-By-Example transcription. On the other hand, if
/// `src` contains no `TTSequence`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>>>,
Expand Down Expand Up @@ -130,13 +130,13 @@ fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
match *t {
// The opening and closing delimiters are both tokens, so they are
// treated as `LisUnconstrained`.
TTDelimited(_, _, ref tts, _) | TTSequence(_, ref tts, _, _) => {
TtDelimited(_, _, ref tts, _) | TtSequence(_, ref tts, _, _) => {
tts.iter().fold(LisUnconstrained, |size, tt| {
size + lockstep_iter_size(tt, r)
})
},
TTToken(..) => LisUnconstrained,
TTNonterminal(_, name) => match *lookup_cur_matched(r, name) {
TtToken(..) => LisUnconstrained,
TtNonterminal(_, name) => match *lookup_cur_matched(r, name) {
MatchedNonterminal(_) => LisUnconstrained,
MatchedSeq(ref ads, _) => LisConstraint(ads.len(), name)
},
Expand Down Expand Up @@ -194,15 +194,15 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
}
}
}
loop { /* because it's easiest, this handles `TTDelimited` not starting
with a `TTToken`, 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 {
TTDelimited(_, open, tts, close) => {
TtDelimited(_, open, tts, close) => {
let mut forest = Vec::with_capacity(1 + tts.len() + 1);
forest.push(open.to_tt());
forest.extend(tts.iter().map(|x| (*x).clone()));
Expand All @@ -216,15 +216,15 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
});
// if this could be 0-length, we'd need to potentially recur here
}
TTToken(sp, tok) => {
TtToken(sp, tok) => {
r.cur_span = sp;
r.cur_tok = tok;
r.stack.last_mut().unwrap().idx += 1;
return ret_val;
}
TTSequence(sp, tts, sep, zerok) => {
TtSequence(sp, tts, sep, zerok) => {
// FIXME(pcwalton): Bad copy.
match lockstep_iter_size(&TTSequence(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 */
Expand Down Expand Up @@ -259,7 +259,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
}
}
// FIXME #2887: think about span stuff here
TTNonterminal(sp, ident) => {
TtNonterminal(sp, ident) => {
r.stack.last_mut().unwrap().idx += 1;
match *lookup_cur_matched(r, ident) {
/* sidestep the interpolation tricks for ident because
Expand Down
16 changes: 8 additions & 8 deletions src/libsyntax/fold.rs
Expand Up @@ -569,10 +569,10 @@ pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg {

pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
match *tt {
TTToken(span, ref tok) =>
TTToken(span, fld.fold_token(tok.clone())),
TTDelimited(span, ref open, ref tts, ref close) =>
TTDelimited(span,
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())
Expand All @@ -582,13 +582,13 @@ pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
span: close.span,
token: fld.fold_token(close.token.clone())
}),
TTSequence(span, ref pattern, ref sep, is_optional) =>
TTSequence(span,
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))
TtNonterminal(sp,ref ident) =>
TtNonterminal(sp,fld.fold_ident(*ident))
}
}

Expand Down

0 comments on commit dfb4163

Please sign in to comment.