rollup merge of #18430 : bjz/token
Conflicts: src/libsyntax/parse/parser.rs
This commit is contained in:
commit
5d6241ddaf
17 changed files with 371 additions and 375 deletions
|
@ -59,7 +59,7 @@ fn parse_token_list(file: &str) -> HashMap<String, Token> {
|
|||
"FLOAT_SUFFIX" => id(),
|
||||
"INT_SUFFIX" => id(),
|
||||
"SHL" => token::BinOp(token::Shl),
|
||||
"LBRACE" => token::LBrace,
|
||||
"LBRACE" => token::OpenDelim(token::Brace),
|
||||
"RARROW" => token::Rarrow,
|
||||
"LIT_STR" => token::LitStr(Name(0)),
|
||||
"DOTDOT" => token::DotDot,
|
||||
|
@ -67,12 +67,12 @@ fn parse_token_list(file: &str) -> HashMap<String, Token> {
|
|||
"DOTDOTDOT" => token::DotDotDot,
|
||||
"NOT" => token::Not,
|
||||
"AND" => token::BinOp(token::And),
|
||||
"LPAREN" => token::LParen,
|
||||
"LPAREN" => token::OpenDelim(token::Paren),
|
||||
"ANDAND" => token::AndAnd,
|
||||
"AT" => token::At,
|
||||
"LBRACKET" => token::LBracket,
|
||||
"LBRACKET" => token::OpenDelim(token::Bracket),
|
||||
"LIT_STR_RAW" => token::LitStrRaw(Name(0), 0),
|
||||
"RPAREN" => token::RParen,
|
||||
"RPAREN" => token::CloseDelim(token::Paren),
|
||||
"SLASH" => token::BinOp(token::Slash),
|
||||
"COMMA" => token::Comma,
|
||||
"LIFETIME" => token::Lifetime(ast::Ident { name: Name(0), ctxt: 0 }),
|
||||
|
@ -83,7 +83,7 @@ fn parse_token_list(file: &str) -> HashMap<String, Token> {
|
|||
"LIT_CHAR" => token::LitChar(Name(0)),
|
||||
"LIT_BYTE" => token::LitByte(Name(0)),
|
||||
"EQ" => token::Eq,
|
||||
"RBRACKET" => token::RBracket,
|
||||
"RBRACKET" => token::CloseDelim(token::Bracket),
|
||||
"COMMENT" => token::Comment,
|
||||
"DOC_COMMENT" => token::DocComment(Name(0)),
|
||||
"DOT" => token::Dot,
|
||||
|
@ -91,7 +91,7 @@ fn parse_token_list(file: &str) -> HashMap<String, Token> {
|
|||
"NE" => token::Ne,
|
||||
"GE" => token::Ge,
|
||||
"PERCENT" => token::BinOp(token::Percent),
|
||||
"RBRACE" => token::RBrace,
|
||||
"RBRACE" => token::CloseDelim(token::Brace),
|
||||
"BINOP" => token::BinOp(token::Plus),
|
||||
"POUND" => token::Pound,
|
||||
"OROR" => token::OrOr,
|
||||
|
|
|
@ -145,7 +145,7 @@ impl<'a> SpanUtils<'a> {
|
|||
last_span = None;
|
||||
let mut next = toks.next_token();
|
||||
|
||||
if (next.tok == token::LParen ||
|
||||
if (next.tok == token::OpenDelim(token::Paren) ||
|
||||
next.tok == token::Lt) &&
|
||||
bracket_count == 0 &&
|
||||
prev.tok.is_ident() {
|
||||
|
@ -164,8 +164,8 @@ impl<'a> SpanUtils<'a> {
|
|||
}
|
||||
|
||||
bracket_count += match prev.tok {
|
||||
token::LParen | token::Lt => 1,
|
||||
token::RParen | token::Gt => -1,
|
||||
token::OpenDelim(token::Paren) | token::Lt => 1,
|
||||
token::CloseDelim(token::Paren) | token::Gt => -1,
|
||||
token::BinOp(token::Shr) => -2,
|
||||
_ => 0
|
||||
};
|
||||
|
|
|
@ -97,8 +97,8 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
|
|||
|
||||
// miscellaneous, no highlighting
|
||||
token::Dot | token::DotDot | token::DotDotDot | token::Comma | token::Semi |
|
||||
token::Colon | token::ModSep | token::LArrow | token::LParen |
|
||||
token::RParen | token::LBracket | token::LBrace | token::RBrace |
|
||||
token::Colon | token::ModSep | token::LArrow | token::OpenDelim(_) |
|
||||
token::CloseDelim(token::Brace) | token::CloseDelim(token::Paren) |
|
||||
token::Question => "",
|
||||
token::Dollar => {
|
||||
if lexer.peek().tok.is_ident() {
|
||||
|
@ -118,7 +118,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
|
|||
try!(write!(out, r"<span class='attribute'>#"));
|
||||
continue
|
||||
}
|
||||
token::RBracket => {
|
||||
token::CloseDelim(token::Bracket) => {
|
||||
if is_attribute {
|
||||
is_attribute = false;
|
||||
try!(write!(out, "]</span>"));
|
||||
|
|
|
@ -595,17 +595,38 @@ pub enum CaptureClause {
|
|||
CaptureByRef,
|
||||
}
|
||||
|
||||
/// A token that delimits a sequence of token trees
|
||||
/// A delimited sequence of token trees
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
pub struct Delimiter {
|
||||
pub span: Span,
|
||||
pub token: ::parse::token::Token,
|
||||
pub struct Delimited {
|
||||
/// The type of delimiter
|
||||
pub delim: token::DelimToken,
|
||||
/// The span covering the opening delimiter
|
||||
pub open_span: Span,
|
||||
/// The delimited sequence of token trees
|
||||
pub tts: Vec<TokenTree>,
|
||||
/// The span covering the closing delimiter
|
||||
pub close_span: Span,
|
||||
}
|
||||
|
||||
impl Delimiter {
|
||||
/// Convert the delimiter to a `TtToken`
|
||||
pub fn to_tt(&self) -> TokenTree {
|
||||
TtToken(self.span, self.token.clone())
|
||||
impl Delimited {
|
||||
/// Returns the opening delimiter as a token.
|
||||
pub fn open_token(&self) -> token::Token {
|
||||
token::OpenDelim(self.delim)
|
||||
}
|
||||
|
||||
/// Returns the closing delimiter as a token.
|
||||
pub fn close_token(&self) -> token::Token {
|
||||
token::CloseDelim(self.delim)
|
||||
}
|
||||
|
||||
/// Returns the opening delimiter as a token tree.
|
||||
pub fn open_tt(&self) -> TokenTree {
|
||||
TtToken(self.open_span, self.open_token())
|
||||
}
|
||||
|
||||
/// Returns the closing delimiter as a token tree.
|
||||
pub fn close_tt(&self) -> TokenTree {
|
||||
TtToken(self.close_span, self.close_token())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -635,15 +656,15 @@ pub enum KleeneOp {
|
|||
#[doc="For macro invocations; parsing is delegated to the macro"]
|
||||
pub enum TokenTree {
|
||||
/// A single token
|
||||
TtToken(Span, ::parse::token::Token),
|
||||
TtToken(Span, token::Token),
|
||||
/// A delimited sequence of token trees
|
||||
TtDelimited(Span, Rc<(Delimiter, Vec<TokenTree>, Delimiter)>),
|
||||
TtDelimited(Span, Rc<Delimited>),
|
||||
|
||||
// These only make sense for right-hand-sides of MBE macros:
|
||||
|
||||
/// A Kleene-style repetition sequence with an optional separator.
|
||||
// FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST.
|
||||
TtSequence(Span, Rc<Vec<TokenTree>>, Option<::parse::token::Token>, KleeneOp),
|
||||
TtSequence(Span, Rc<Vec<TokenTree>>, Option<token::Token>, KleeneOp),
|
||||
/// A syntactic variable that will be filled in by macro expansion.
|
||||
TtNonterminal(Span, Ident)
|
||||
}
|
||||
|
@ -715,10 +736,10 @@ pub type Matcher = Spanned<Matcher_>;
|
|||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
pub enum Matcher_ {
|
||||
/// Match one token
|
||||
MatchTok(::parse::token::Token),
|
||||
MatchTok(token::Token),
|
||||
/// Match repetitions of a sequence: body, separator, Kleene operator,
|
||||
/// lo, hi position-in-match-array used:
|
||||
MatchSeq(Vec<Matcher> , Option<::parse::token::Token>, KleeneOp, uint, uint),
|
||||
MatchSeq(Vec<Matcher>, Option<token::Token>, KleeneOp, uint, uint),
|
||||
/// Parse a Rust NT: name to bind, name of NT, position in match array:
|
||||
MatchNonterminal(Ident, Ident, uint)
|
||||
}
|
||||
|
|
|
@ -84,9 +84,9 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
|
||||
let span = p.last_span;
|
||||
|
||||
p.expect(&token::LParen);
|
||||
p.expect(&token::OpenDelim(token::Paren));
|
||||
let out = p.parse_expr();
|
||||
p.expect(&token::RParen);
|
||||
p.expect(&token::CloseDelim(token::Paren));
|
||||
|
||||
// Expands a read+write operand into two operands.
|
||||
//
|
||||
|
@ -129,9 +129,9 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
cx.span_err(p.last_span, "input operand constraint contains '+'");
|
||||
}
|
||||
|
||||
p.expect(&token::LParen);
|
||||
p.expect(&token::OpenDelim(token::Paren));
|
||||
let input = p.parse_expr();
|
||||
p.expect(&token::RParen);
|
||||
p.expect(&token::CloseDelim(token::Paren));
|
||||
|
||||
inputs.push((constraint, input));
|
||||
}
|
||||
|
|
|
@ -531,6 +531,15 @@ fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOpToken) -> P<ast::Expr> {
|
|||
mk_token_path(cx, sp, name)
|
||||
}
|
||||
|
||||
fn mk_delim(cx: &ExtCtxt, sp: Span, delim: token::DelimToken) -> P<ast::Expr> {
|
||||
let name = match delim {
|
||||
token::Paren => "Paren",
|
||||
token::Bracket => "Bracket",
|
||||
token::Brace => "Brace",
|
||||
};
|
||||
mk_token_path(cx, sp, name)
|
||||
}
|
||||
|
||||
#[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot
|
||||
fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {
|
||||
match *tok {
|
||||
|
@ -542,6 +551,15 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {
|
|||
vec!(mk_binop(cx, sp, binop)));
|
||||
}
|
||||
|
||||
token::OpenDelim(delim) => {
|
||||
return cx.expr_call(sp, mk_token_path(cx, sp, "OpenDelim"),
|
||||
vec![mk_delim(cx, sp, delim)]);
|
||||
}
|
||||
token::CloseDelim(delim) => {
|
||||
return cx.expr_call(sp, mk_token_path(cx, sp, "CloseDelim"),
|
||||
vec![mk_delim(cx, sp, delim)]);
|
||||
}
|
||||
|
||||
token::LitByte(i) => {
|
||||
let e_byte = mk_name(cx, sp, i.ident());
|
||||
|
||||
|
@ -625,12 +643,6 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {
|
|||
token::RArrow => "RArrow",
|
||||
token::LArrow => "LArrow",
|
||||
token::FatArrow => "FatArrow",
|
||||
token::LParen => "LParen",
|
||||
token::RParen => "RParen",
|
||||
token::LBracket => "LBracket",
|
||||
token::RBracket => "RBracket",
|
||||
token::LBrace => "LBrace",
|
||||
token::RBrace => "RBrace",
|
||||
token::Pound => "Pound",
|
||||
token::Dollar => "Dollar",
|
||||
token::Underscore => "Underscore",
|
||||
|
@ -640,7 +652,6 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {
|
|||
mk_token_path(cx, sp, name)
|
||||
}
|
||||
|
||||
|
||||
fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {
|
||||
match *tt {
|
||||
ast::TtToken(sp, ref tok) => {
|
||||
|
@ -656,10 +667,9 @@ fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {
|
|||
vec!(cx.stmt_expr(e_push))
|
||||
},
|
||||
ast::TtDelimited(sp, ref delimed) => {
|
||||
let (ref open, ref tts, ref close) = **delimed;
|
||||
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())
|
||||
mk_tt(cx, sp, &delimed.open_tt()).into_iter()
|
||||
.chain(delimed.tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter()))
|
||||
.chain(mk_tt(cx, sp, &delimed.close_tt()).into_iter())
|
||||
.collect()
|
||||
},
|
||||
ast::TtSequence(..) => panic!("TtSequence in quote!"),
|
||||
|
|
|
@ -355,10 +355,8 @@ pub fn parse(sess: &ParseSess,
|
|||
// Built-in nonterminals never start with these tokens,
|
||||
// so we can eliminate them from consideration.
|
||||
match tok {
|
||||
token::RParen |
|
||||
token::RBrace |
|
||||
token::RBracket => {},
|
||||
_ => bb_eis.push(ei)
|
||||
token::CloseDelim(_) => {},
|
||||
_ => bb_eis.push(ei),
|
||||
}
|
||||
}
|
||||
MatchTok(ref t) => {
|
||||
|
|
|
@ -172,10 +172,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
|
|||
MatchedNonterminal(NtTT(ref tt)) => {
|
||||
match **tt {
|
||||
// ignore delimiters
|
||||
TtDelimited(_, ref delimed) => {
|
||||
let (_, ref tts, _) = **delimed;
|
||||
tts.clone()
|
||||
},
|
||||
TtDelimited(_, ref delimed) => delimed.tts.clone(),
|
||||
_ => cx.span_fatal(sp, "macro rhs must be delimited"),
|
||||
}
|
||||
},
|
||||
|
|
|
@ -129,8 +129,7 @@ impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
|
|||
fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
|
||||
match *t {
|
||||
TtDelimited(_, ref delimed) => {
|
||||
let (_, ref tts, _) = **delimed;
|
||||
tts.iter().fold(LisUnconstrained, |size, tt| {
|
||||
delimed.tts.iter().fold(LisUnconstrained, |size, tt| {
|
||||
size + lockstep_iter_size(tt, r)
|
||||
})
|
||||
},
|
||||
|
@ -207,14 +206,13 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
|
|||
};
|
||||
match t {
|
||||
TtDelimited(_, ref delimed) => {
|
||||
let (ref open, ref tts, ref close) = **delimed;
|
||||
let mut forest = Vec::with_capacity(1 + tts.len() + 1);
|
||||
forest.push(open.to_tt());
|
||||
forest.extend(tts.iter().map(|x| (*x).clone()));
|
||||
forest.push(close.to_tt());
|
||||
let mut tts = Vec::with_capacity(1 + delimed.tts.len() + 1);
|
||||
tts.push(delimed.open_tt());
|
||||
tts.extend(delimed.tts.iter().map(|tt| tt.clone()));
|
||||
tts.push(delimed.close_tt());
|
||||
|
||||
r.stack.push(TtFrame {
|
||||
forest: Rc::new(forest),
|
||||
forest: Rc::new(tts),
|
||||
idx: 0,
|
||||
dotdotdoted: false,
|
||||
sep: None
|
||||
|
|
|
@ -572,18 +572,14 @@ pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
|
|||
TtToken(span, ref tok) =>
|
||||
TtToken(span, fld.fold_token(tok.clone())),
|
||||
TtDelimited(span, ref delimed) => {
|
||||
let (ref open, ref tts, ref close) = **delimed;
|
||||
TtDelimited(span, Rc::new((
|
||||
Delimiter {
|
||||
span: open.span,
|
||||
token: fld.fold_token(open.token.clone())
|
||||
},
|
||||
fld.fold_tts(tts.as_slice()),
|
||||
Delimiter {
|
||||
span: close.span,
|
||||
token: fld.fold_token(close.token.clone())
|
||||
},
|
||||
)))
|
||||
TtDelimited(span, Rc::new(
|
||||
Delimited {
|
||||
delim: delimed.delim,
|
||||
open_span: delimed.open_span,
|
||||
tts: fld.fold_tts(delimed.tts.as_slice()),
|
||||
close_span: delimed.close_span,
|
||||
}
|
||||
))
|
||||
},
|
||||
TtSequence(span, ref pattern, ref sep, is_optional) =>
|
||||
TtSequence(span,
|
||||
|
|
|
@ -81,10 +81,10 @@ impl<'a> ParserAttr for Parser<'a> {
|
|||
ast::AttrOuter
|
||||
};
|
||||
|
||||
self.expect(&token::LBracket);
|
||||
self.expect(&token::OpenDelim(token::Bracket));
|
||||
let meta_item = self.parse_meta_item();
|
||||
let hi = self.span.hi;
|
||||
self.expect(&token::RBracket);
|
||||
self.expect(&token::CloseDelim(token::Bracket));
|
||||
|
||||
(mk_sp(lo, hi), meta_item, style)
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ impl<'a> ParserAttr for Parser<'a> {
|
|||
let hi = self.span.hi;
|
||||
P(spanned(lo, hi, ast::MetaNameValue(name, lit)))
|
||||
}
|
||||
token::LParen => {
|
||||
token::OpenDelim(token::Paren) => {
|
||||
let inner_items = self.parse_meta_seq();
|
||||
let hi = self.span.hi;
|
||||
P(spanned(lo, hi, ast::MetaList(name, inner_items)))
|
||||
|
@ -208,15 +208,15 @@ impl<'a> ParserAttr for Parser<'a> {
|
|||
|
||||
/// matches meta_seq = ( COMMASEP(meta_item) )
|
||||
fn parse_meta_seq(&mut self) -> Vec<P<ast::MetaItem>> {
|
||||
self.parse_seq(&token::LParen,
|
||||
&token::RParen,
|
||||
self.parse_seq(&token::OpenDelim(token::Paren),
|
||||
&token::CloseDelim(token::Paren),
|
||||
seq_sep_trailing_disallowed(token::Comma),
|
||||
|p| p.parse_meta_item()).node
|
||||
}
|
||||
|
||||
fn parse_optional_meta(&mut self) -> Vec<P<ast::MetaItem>> {
|
||||
match self.token {
|
||||
token::LParen => self.parse_meta_seq(),
|
||||
token::OpenDelim(token::Paren) => self.parse_meta_seq(),
|
||||
_ => Vec::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -967,12 +967,12 @@ impl<'a> StringReader<'a> {
|
|||
token::Dot
|
||||
};
|
||||
}
|
||||
'(' => { self.bump(); return token::LParen; }
|
||||
')' => { self.bump(); return token::RParen; }
|
||||
'{' => { self.bump(); return token::LBrace; }
|
||||
'}' => { self.bump(); return token::RBrace; }
|
||||
'[' => { self.bump(); return token::LBracket; }
|
||||
']' => { self.bump(); return token::RBracket; }
|
||||
'(' => { self.bump(); return token::OpenDelim(token::Paren); }
|
||||
')' => { self.bump(); return token::CloseDelim(token::Paren); }
|
||||
'{' => { self.bump(); return token::OpenDelim(token::Brace); }
|
||||
'}' => { self.bump(); return token::CloseDelim(token::Brace); }
|
||||
'[' => { self.bump(); return token::OpenDelim(token::Bracket); }
|
||||
']' => { self.bump(); return token::CloseDelim(token::Bracket); }
|
||||
'@' => { self.bump(); return token::At; }
|
||||
'#' => { self.bump(); return token::Pound; }
|
||||
'~' => { self.bump(); return token::Tilde; }
|
||||
|
|
|
@ -799,29 +799,23 @@ mod test {
|
|||
ast::TtDelimited(_, ref macro_delimed)]
|
||||
if name_macro_rules.as_str() == "macro_rules"
|
||||
&& name_zip.as_str() == "zip" => {
|
||||
let (ref macro_open, ref macro_tts, ref macro_close) = **macro_delimed;
|
||||
match (macro_open, macro_tts.as_slice(), macro_close) {
|
||||
(&ast::Delimiter { token: token::LParen, .. },
|
||||
match macro_delimed.tts.as_slice() {
|
||||
[ast::TtDelimited(_, ref first_delimed),
|
||||
ast::TtToken(_, token::FatArrow),
|
||||
ast::TtDelimited(_, ref second_delimed)],
|
||||
&ast::Delimiter { token: token::RParen, .. }) => {
|
||||
let (ref first_open, ref first_tts, ref first_close) = **first_delimed;
|
||||
match (first_open, first_tts.as_slice(), first_close) {
|
||||
(&ast::Delimiter { token: token::LParen, .. },
|
||||
ast::TtDelimited(_, ref second_delimed)]
|
||||
if macro_delimed.delim == token::Paren => {
|
||||
match first_delimed.tts.as_slice() {
|
||||
[ast::TtToken(_, token::Dollar),
|
||||
ast::TtToken(_, token::Ident(name, token::Plain))],
|
||||
&ast::Delimiter { token: token::RParen, .. })
|
||||
if name.as_str() == "a" => {},
|
||||
ast::TtToken(_, token::Ident(name, token::Plain))]
|
||||
if first_delimed.delim == token::Paren
|
||||
&& name.as_str() == "a" => {},
|
||||
_ => panic!("value 3: {}", **first_delimed),
|
||||
}
|
||||
let (ref second_open, ref second_tts, ref second_close) = **second_delimed;
|
||||
match (second_open, second_tts.as_slice(), second_close) {
|
||||
(&ast::Delimiter { token: token::LParen, .. },
|
||||
match second_delimed.tts.as_slice() {
|
||||
[ast::TtToken(_, token::Dollar),
|
||||
ast::TtToken(_, token::Ident(name, token::Plain))],
|
||||
&ast::Delimiter { token: token::RParen, .. })
|
||||
if name.as_str() == "a" => {},
|
||||
ast::TtToken(_, token::Ident(name, token::Plain))]
|
||||
if second_delimed.delim == token::Paren
|
||||
&& name.as_str() == "a" => {},
|
||||
_ => panic!("value 4: {}", **second_delimed),
|
||||
}
|
||||
},
|
||||
|
@ -867,12 +861,10 @@ mod test {
|
|||
\"variant\":\"TtDelimited\",\
|
||||
\"fields\":[\
|
||||
null,\
|
||||
[\
|
||||
{\
|
||||
\"span\":null,\
|
||||
\"token\":\"LParen\"\
|
||||
},\
|
||||
[\
|
||||
\"delim\":\"Paren\",\
|
||||
\"open_span\":null,\
|
||||
\"tts\":[\
|
||||
{\
|
||||
\"variant\":\"TtToken\",\
|
||||
\"fields\":[\
|
||||
|
@ -907,23 +899,18 @@ mod test {
|
|||
]\
|
||||
}\
|
||||
],\
|
||||
{\
|
||||
\"span\":null,\
|
||||
\"token\":\"RParen\"\
|
||||
\"close_span\":null\
|
||||
}\
|
||||
]\
|
||||
]\
|
||||
},\
|
||||
{\
|
||||
\"variant\":\"TtDelimited\",\
|
||||
\"fields\":[\
|
||||
null,\
|
||||
[\
|
||||
{\
|
||||
\"span\":null,\
|
||||
\"token\":\"LBrace\"\
|
||||
},\
|
||||
[\
|
||||
\"delim\":\"Brace\",\
|
||||
\"open_span\":null,\
|
||||
\"tts\":[\
|
||||
{\
|
||||
\"variant\":\"TtToken\",\
|
||||
\"fields\":[\
|
||||
|
@ -945,12 +932,9 @@ mod test {
|
|||
]\
|
||||
}\
|
||||
],\
|
||||
{\
|
||||
\"span\":null,\
|
||||
\"token\":\"RBrace\"\
|
||||
\"close_span\":null\
|
||||
}\
|
||||
]\
|
||||
]\
|
||||
}\
|
||||
]".to_string()
|
||||
);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -56,12 +56,6 @@ use std::rc::Rc;
|
|||
#[cfg(stage0)] pub use self::RArrow as RARROW;
|
||||
#[cfg(stage0)] pub use self::LArrow as LARROW;
|
||||
#[cfg(stage0)] pub use self::FatArrow as FAT_ARROW;
|
||||
#[cfg(stage0)] pub use self::LParen as LPAREN;
|
||||
#[cfg(stage0)] pub use self::RParen as RPAREN;
|
||||
#[cfg(stage0)] pub use self::LBracket as LBRACKET;
|
||||
#[cfg(stage0)] pub use self::RBracket as RBRACKET;
|
||||
#[cfg(stage0)] pub use self::LBrace as LBRACE;
|
||||
#[cfg(stage0)] pub use self::RBrace as RBRACE;
|
||||
#[cfg(stage0)] pub use self::Pound as POUND;
|
||||
#[cfg(stage0)] pub use self::Dollar as DOLLAR;
|
||||
#[cfg(stage0)] pub use self::Question as QUESTION;
|
||||
|
@ -82,6 +76,12 @@ use std::rc::Rc;
|
|||
#[cfg(stage0)] pub use self::Comment as COMMENT;
|
||||
#[cfg(stage0)] pub use self::Shebang as SHEBANG;
|
||||
#[cfg(stage0)] pub use self::Eof as EOF;
|
||||
#[cfg(stage0)] pub const LPAREN: Token = OpenDelim(Paren);
|
||||
#[cfg(stage0)] pub const RPAREN: Token = CloseDelim(Paren);
|
||||
#[cfg(stage0)] pub const LBRACKET: Token = OpenDelim(Bracket);
|
||||
#[cfg(stage0)] pub const RBRACKET: Token = CloseDelim(Bracket);
|
||||
#[cfg(stage0)] pub const LBRACE: Token = OpenDelim(Brace);
|
||||
#[cfg(stage0)] pub const RBRACE: Token = CloseDelim(Brace);
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)]
|
||||
|
@ -98,6 +98,17 @@ pub enum BinOpToken {
|
|||
Shr,
|
||||
}
|
||||
|
||||
/// A delimeter token
|
||||
#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)]
|
||||
pub enum DelimToken {
|
||||
/// A round parenthesis: `(` or `)`
|
||||
Paren,
|
||||
/// A square bracket: `[` or `]`
|
||||
Bracket,
|
||||
/// A curly brace: `{` or `}`
|
||||
Brace,
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[allow(non_uppercase_statics)]
|
||||
pub const ModName: bool = true;
|
||||
|
@ -143,15 +154,13 @@ pub enum Token {
|
|||
RArrow,
|
||||
LArrow,
|
||||
FatArrow,
|
||||
LParen,
|
||||
RParen,
|
||||
LBracket,
|
||||
RBracket,
|
||||
LBrace,
|
||||
RBrace,
|
||||
Pound,
|
||||
Dollar,
|
||||
Question,
|
||||
/// An opening delimeter, eg. `{`
|
||||
OpenDelim(DelimToken),
|
||||
/// A closing delimeter, eg. `}`
|
||||
CloseDelim(DelimToken),
|
||||
|
||||
/* Literals */
|
||||
LitByte(ast::Name),
|
||||
|
@ -192,9 +201,7 @@ impl Token {
|
|||
/// Returns `true` if the token can appear at the start of an expression.
|
||||
pub fn can_begin_expr(&self) -> bool {
|
||||
match *self {
|
||||
LParen => true,
|
||||
LBrace => true,
|
||||
LBracket => true,
|
||||
OpenDelim(_) => true,
|
||||
Ident(_, _) => true,
|
||||
Underscore => true,
|
||||
Tilde => true,
|
||||
|
@ -223,17 +230,6 @@ impl Token {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the matching close delimiter if this is an open delimiter,
|
||||
/// otherwise `None`.
|
||||
pub fn get_close_delimiter(&self) -> Option<Token> {
|
||||
match *self {
|
||||
LParen => Some(RParen),
|
||||
LBrace => Some(RBrace),
|
||||
LBracket => Some(RBracket),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is any literal
|
||||
pub fn is_lit(&self) -> bool {
|
||||
match *self {
|
||||
|
@ -396,20 +392,20 @@ impl Token {
|
|||
#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)]
|
||||
/// For interpolation during macro expansion.
|
||||
pub enum Nonterminal {
|
||||
NtItem( P<ast::Item>),
|
||||
NtItem(P<ast::Item>),
|
||||
NtBlock(P<ast::Block>),
|
||||
NtStmt( P<ast::Stmt>),
|
||||
NtPat( P<ast::Pat>),
|
||||
NtExpr( P<ast::Expr>),
|
||||
NtTy( P<ast::Ty>),
|
||||
NtStmt(P<ast::Stmt>),
|
||||
NtPat(P<ast::Pat>),
|
||||
NtExpr(P<ast::Expr>),
|
||||
NtTy(P<ast::Ty>),
|
||||
#[cfg(stage0)]
|
||||
NtIdent(Box<ast::Ident>, bool),
|
||||
#[cfg(not(stage0))]
|
||||
NtIdent(Box<ast::Ident>, IdentStyle),
|
||||
/// Stuff inside brackets for attributes
|
||||
NtMeta( P<ast::MetaItem>),
|
||||
NtMeta(P<ast::MetaItem>),
|
||||
NtPath(Box<ast::Path>),
|
||||
NtTT( P<ast::TokenTree>), // needs P'ed to break a circularity
|
||||
NtTT(P<ast::TokenTree>), // needs P'ed to break a circularity
|
||||
NtMatchers(Vec<ast::Matcher>)
|
||||
}
|
||||
|
||||
|
|
|
@ -225,12 +225,12 @@ pub fn token_to_string(tok: &Token) -> String {
|
|||
token::RArrow => "->".into_string(),
|
||||
token::LArrow => "<-".into_string(),
|
||||
token::FatArrow => "=>".into_string(),
|
||||
token::LParen => "(".into_string(),
|
||||
token::RParen => ")".into_string(),
|
||||
token::LBracket => "[".into_string(),
|
||||
token::RBracket => "]".into_string(),
|
||||
token::LBrace => "{".into_string(),
|
||||
token::RBrace => "}".into_string(),
|
||||
token::OpenDelim(token::Paren) => "(".into_string(),
|
||||
token::CloseDelim(token::Paren) => ")".into_string(),
|
||||
token::OpenDelim(token::Bracket) => "[".into_string(),
|
||||
token::CloseDelim(token::Bracket) => "]".into_string(),
|
||||
token::OpenDelim(token::Brace) => "{".into_string(),
|
||||
token::CloseDelim(token::Brace) => "}".into_string(),
|
||||
token::Pound => "#".into_string(),
|
||||
token::Dollar => "$".into_string(),
|
||||
token::Question => "?".into_string(),
|
||||
|
@ -1121,12 +1121,11 @@ impl<'a> State<'a> {
|
|||
pub fn print_tt(&mut self, tt: &ast::TokenTree) -> IoResult<()> {
|
||||
match *tt {
|
||||
ast::TtDelimited(_, ref delimed) => {
|
||||
let (ref open, ref tts, ref close) = **delimed;
|
||||
try!(word(&mut self.s, token_to_string(&open.token).as_slice()));
|
||||
try!(word(&mut self.s, token_to_string(&delimed.open_token()).as_slice()));
|
||||
try!(space(&mut self.s));
|
||||
try!(self.print_tts(tts.as_slice()));
|
||||
try!(self.print_tts(delimed.tts.as_slice()));
|
||||
try!(space(&mut self.s));
|
||||
word(&mut self.s, token_to_string(&close.token).as_slice())
|
||||
word(&mut self.s, token_to_string(&delimed.close_token()).as_slice())
|
||||
},
|
||||
ast::TtToken(_, ref tk) => {
|
||||
try!(word(&mut self.s, token_to_string(tk).as_slice()));
|
||||
|
|
|
@ -8,4 +8,4 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
type t = { f: () }; //~ ERROR expected type, found token LBrace
|
||||
type t = { f: () }; //~ ERROR expected type, found token OpenDelim(Brace)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue