rustfmt syntax::parse

This commit is contained in:
Tshepang Lekhonkhobe
2016-01-27 21:42:26 +02:00
parent b8b18aac12
commit bbdef0ce59
3 changed files with 49 additions and 49 deletions

View File

@@ -22,26 +22,25 @@ impl<'a> Parser<'a> {
pub fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> { pub fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
let mut attrs: Vec<ast::Attribute> = Vec::new(); let mut attrs: Vec<ast::Attribute> = Vec::new();
loop { loop {
debug!("parse_outer_attributes: self.token={:?}", debug!("parse_outer_attributes: self.token={:?}", self.token);
self.token);
match self.token { match self.token {
token::Pound => { token::Pound => {
attrs.push(try!(self.parse_attribute(false))); attrs.push(try!(self.parse_attribute(false)));
} }
token::DocComment(s) => { token::DocComment(s) => {
let attr = ::attr::mk_sugared_doc_attr( let attr = ::attr::mk_sugared_doc_attr(
attr::mk_attr_id(), attr::mk_attr_id(),
self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)), self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)),
self.span.lo, self.span.lo,
self.span.hi self.span.hi
); );
if attr.node.style != ast::AttrStyle::Outer { if attr.node.style != ast::AttrStyle::Outer {
return Err(self.fatal("expected outer comment")); return Err(self.fatal("expected outer comment"));
}
attrs.push(attr);
self.bump();
} }
attrs.push(attr); _ => break,
self.bump();
}
_ => break
} }
} }
return Ok(attrs); return Ok(attrs);
@@ -53,24 +52,27 @@ impl<'a> Parser<'a> {
/// attribute /// attribute
pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, ast::Attribute> { pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, ast::Attribute> {
debug!("parse_attributes: permit_inner={:?} self.token={:?}", debug!("parse_attributes: permit_inner={:?} self.token={:?}",
permit_inner, self.token); permit_inner,
self.token);
let (span, value, mut style) = match self.token { let (span, value, mut style) = match self.token {
token::Pound => { token::Pound => {
let lo = self.span.lo; let lo = self.span.lo;
self.bump(); self.bump();
if permit_inner { self.expected_tokens.push(TokenType::Token(token::Not)); } if permit_inner {
self.expected_tokens.push(TokenType::Token(token::Not));
}
let style = if self.token == token::Not { let style = if self.token == token::Not {
self.bump(); self.bump();
if !permit_inner { if !permit_inner {
let span = self.span; let span = self.span;
self.diagnostic().struct_span_err(span, self.diagnostic()
"an inner attribute is not permitted in \ .struct_span_err(span,
this context") "an inner attribute is not permitted in this context")
.fileline_help(span, .fileline_help(span,
"place inner attribute at the top of \ "place inner attribute at the top of the module or \
the module or block") block")
.emit() .emit()
} }
ast::AttrStyle::Inner ast::AttrStyle::Inner
} else { } else {
@@ -92,8 +94,9 @@ impl<'a> Parser<'a> {
if permit_inner && self.token == token::Semi { if permit_inner && self.token == token::Semi {
self.bump(); self.bump();
self.span_warn(span, "this inner attribute syntax is deprecated. \ self.span_warn(span,
The new syntax is `#![foo]`, with a bang and no semicolon"); "this inner attribute syntax is deprecated. The new syntax is \
`#![foo]`, with a bang and no semicolon");
style = ast::AttrStyle::Inner; style = ast::AttrStyle::Inner;
} }
@@ -103,8 +106,8 @@ impl<'a> Parser<'a> {
id: attr::mk_attr_id(), id: attr::mk_attr_id(),
style: style, style: style,
value: value, value: value,
is_sugared_doc: false is_sugared_doc: false,
} },
}) })
} }
@@ -139,7 +142,7 @@ impl<'a> Parser<'a> {
break; break;
} }
} }
_ => break _ => break,
} }
} }
Ok(attrs) Ok(attrs)
@@ -150,10 +153,8 @@ impl<'a> Parser<'a> {
/// | IDENT meta_seq /// | IDENT meta_seq
pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> { pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
let nt_meta = match self.token { let nt_meta = match self.token {
token::Interpolated(token::NtMeta(ref e)) => { token::Interpolated(token::NtMeta(ref e)) => Some(e.clone()),
Some(e.clone()) _ => None,
}
_ => None
}; };
match nt_meta { match nt_meta {
@@ -176,9 +177,8 @@ impl<'a> Parser<'a> {
match lit.node { match lit.node {
ast::LitStr(..) => {} ast::LitStr(..) => {}
_ => { _ => {
self.span_err( self.span_err(lit.span,
lit.span, "non-string literals are not allowed in meta-items");
"non-string literals are not allowed in meta-items");
} }
} }
let hi = self.span.hi; let hi = self.span.hi;

View File

@@ -23,22 +23,22 @@ use ast;
/// isn't parsed as (if true {...} else {...} | x) | 5 /// isn't parsed as (if true {...} else {...} | x) | 5
pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
match e.node { match e.node {
ast::ExprIf(..) ast::ExprIf(..) |
| ast::ExprIfLet(..) ast::ExprIfLet(..) |
| ast::ExprMatch(..) ast::ExprMatch(..) |
| ast::ExprBlock(_) ast::ExprBlock(_) |
| ast::ExprWhile(..) ast::ExprWhile(..) |
| ast::ExprWhileLet(..) ast::ExprWhileLet(..) |
| ast::ExprLoop(..) ast::ExprLoop(..) |
| ast::ExprForLoop(..) => false, ast::ExprForLoop(..) => false,
_ => true _ => true,
} }
} }
pub fn expr_is_simple_block(e: &ast::Expr) -> bool { pub fn expr_is_simple_block(e: &ast::Expr) -> bool {
match e.node { match e.node {
ast::ExprBlock(ref block) => block.rules == ast::DefaultBlock, ast::ExprBlock(ref block) => block.rules == ast::DefaultBlock,
_ => false _ => false,
} }
} }
@@ -50,11 +50,11 @@ pub fn stmt_ends_with_semi(stmt: &ast::Stmt_) -> bool {
ast::StmtDecl(ref d, _) => { ast::StmtDecl(ref d, _) => {
match d.node { match d.node {
ast::DeclLocal(_) => true, ast::DeclLocal(_) => true,
ast::DeclItem(_) => false ast::DeclItem(_) => false,
} }
} }
ast::StmtExpr(ref e, _) => { expr_requires_semi_to_be_stmt(e) } ast::StmtExpr(ref e, _) => expr_requires_semi_to_be_stmt(e),
ast::StmtSemi(..) => { false } ast::StmtSemi(..) => false,
ast::StmtMac(..) => { false } ast::StmtMac(..) => false,
} }
} }

View File

@@ -16,7 +16,7 @@ use parse::token;
/// and whether a trailing separator is allowed. /// and whether a trailing separator is allowed.
pub struct SeqSep { pub struct SeqSep {
pub sep: Option<token::Token>, pub sep: Option<token::Token>,
pub trailing_sep_allowed: bool pub trailing_sep_allowed: bool,
} }
pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep { pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep {