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