Cut out a bunch of Result and panictry! boilerplate from libsyntax.

[breaking-change] if you use any of the changed functions, you'll need to remove a try! or panictry!
This commit is contained in:
Nick Cameron 2015-12-31 12:11:53 +13:00
parent efb5a9a9f0
commit 9023c659af
12 changed files with 318 additions and 313 deletions

View File

@ -826,7 +826,7 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
let mut es = Vec::new();
while p.token != token::Eof {
es.push(cx.expander().fold_expr(panictry!(p.parse_expr())));
if panictry!(p.eat(&token::Comma)){
if p.eat(&token::Comma) {
continue;
}
if p.token != token::Eof {

View File

@ -801,7 +801,7 @@ fn parse_arguments_to_quote(cx: &ExtCtxt, tts: &[TokenTree])
p.quote_depth += 1;
let cx_expr = panictry!(p.parse_expr());
if !panictry!(p.eat(&token::Comma)) {
if !p.eat(&token::Comma) {
let _ = p.diagnostic().fatal("expected token `,`");
}

View File

@ -512,7 +512,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
_ => {}
}
// check at the beginning and the parser checks after each bump
panictry!(p.check_unknown_macro_variable());
p.check_unknown_macro_variable();
match name {
"item" => match panictry!(p.parse_item()) {
Some(i) => token::NtItem(i),
@ -535,7 +535,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
// this could be handled like a token, since it is one
"ident" => match p.token {
token::Ident(sn,b) => {
panictry!(p.bump());
p.bump();
token::NtIdent(Box::new(Spanned::<Ident>{node: sn, span: p.span}),b)
}
_ => {

View File

@ -47,7 +47,7 @@ impl<'a> ParserAnyMacro<'a> {
fn ensure_complete_parse(&self, allow_semi: bool, context: &str) {
let mut parser = self.parser.borrow_mut();
if allow_semi && parser.token == token::Semi {
panictry!(parser.bump())
parser.bump();
}
if parser.token != token::Eof {
let token_str = parser.this_token_to_string();
@ -194,7 +194,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
imported_from,
rhs);
let mut p = Parser::new(cx.parse_sess(), cx.cfg(), Box::new(trncbr));
panictry!(p.check_unknown_macro_variable());
p.check_unknown_macro_variable();
// Let the context choose how to interpret the result.
// Weird, but useful for X-macros.
return Box::new(ParserAnyMacro {

View File

@ -39,7 +39,7 @@ impl<'a> Parser<'a> {
return Err(self.fatal("expected outer comment"));
}
attrs.push(attr);
try!(self.bump());
self.bump();
}
_ => break
}
@ -57,11 +57,11 @@ impl<'a> Parser<'a> {
let (span, value, mut style) = match self.token {
token::Pound => {
let lo = self.span.lo;
try!(self.bump());
self.bump();
if permit_inner { self.expected_tokens.push(TokenType::Token(token::Not)); }
let style = if self.token == token::Not {
try!(self.bump());
self.bump();
if !permit_inner {
let span = self.span;
self.diagnostic().struct_span_err(span,
@ -91,7 +91,7 @@ impl<'a> Parser<'a> {
};
if permit_inner && self.token == token::Semi {
try!(self.bump());
self.bump();
self.span_warn(span, "this inner attribute syntax is deprecated. \
The new syntax is `#![foo]`, with a bang and no semicolon");
style = ast::AttrStyle::Inner;
@ -134,7 +134,7 @@ impl<'a> Parser<'a> {
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), str, lo, hi);
if attr.node.style == ast::AttrStyle::Inner {
attrs.push(attr);
try!(self.bump());
self.bump();
} else {
break;
}
@ -158,7 +158,7 @@ impl<'a> Parser<'a> {
match nt_meta {
Some(meta) => {
try!(self.bump());
self.bump();
return Ok(meta);
}
None => {}
@ -169,7 +169,7 @@ impl<'a> Parser<'a> {
let name = self.id_to_interned_str(ident);
match self.token {
token::Eq => {
try!(self.bump());
self.bump();
let lit = try!(self.parse_lit());
// FIXME #623 Non-string meta items are not serialized correctly;
// just forbid them for now

View File

@ -261,7 +261,7 @@ pub fn tts_to_parser<'a>(sess: &'a ParseSess,
cfg: ast::CrateConfig) -> Parser<'a> {
let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, None, tts);
let mut p = Parser::new(sess, cfg, Box::new(trdr));
panictry!(p.check_unknown_macro_variable());
p.check_unknown_macro_variable();
p
}

File diff suppressed because it is too large Load Diff

View File

@ -113,7 +113,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
p.token != token::ModSep {
if !outputs.is_empty() {
panictry!(p.eat(&token::Comma));
p.eat(&token::Comma);
}
let (constraint, _str_style) = panictry!(p.parse_str());
@ -159,7 +159,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
p.token != token::ModSep {
if !inputs.is_empty() {
panictry!(p.eat(&token::Comma));
p.eat(&token::Comma);
}
let (constraint, _str_style) = panictry!(p.parse_str());
@ -183,7 +183,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
p.token != token::ModSep {
if !clobs.is_empty() {
panictry!(p.eat(&token::Comma));
p.eat(&token::Comma);
}
let (s, _str_style) = panictry!(p.parse_str());
@ -210,7 +210,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
}
if p.token == token::Comma {
panictry!(p.eat(&token::Comma));
p.eat(&token::Comma);
}
}
StateNone => ()
@ -222,12 +222,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
match (&p.token, state.next(), state.next().next()) {
(&token::Colon, StateNone, _) |
(&token::ModSep, _, StateNone) => {
panictry!(p.bump());
p.bump();
break 'statement;
}
(&token::Colon, st, _) |
(&token::ModSep, _, st) => {
panictry!(p.bump());
p.bump();
state = st;
}
(&token::Eof, _, _) => break 'statement,

View File

@ -28,7 +28,7 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
let mut p = cx.new_parser_from_tts(tts);
let cfg = panictry!(p.parse_meta_item());
if !panictry!(p.eat(&token::Eof)){
if !p.eat(&token::Eof) {
cx.span_err(sp, "expected 1 cfg-pattern");
return DummyResult::expr(sp);
}

View File

@ -98,7 +98,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
let fmtstr = panictry!(p.parse_expr());
let mut named = false;
while p.token != token::Eof {
if !panictry!(p.eat(&token::Comma)) {
if !p.eat(&token::Comma) {
ecx.span_err(sp, "expected token: `,`");
return None;
}
@ -107,7 +107,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
named = true;
let ident = match p.token {
token::Ident(i, _) => {
panictry!(p.bump());
p.bump();
i
}
_ if named => {

View File

@ -13,7 +13,6 @@
// (typeof used because it's surprisingly hard to find an unparsed token after a stmt)
macro_rules! m {
() => ( i ; typeof ); //~ ERROR `typeof` is a reserved keyword
//~| ERROR macro expansion ignores token `typeof`
//~| ERROR macro expansion ignores token `typeof`
//~| ERROR macro expansion ignores token `;`
//~| ERROR macro expansion ignores token `;`
@ -29,5 +28,5 @@ fn main() {
m!() => {} //~ NOTE the usage of `m!` is likely invalid in pattern context
}
m!(); //~ NOTE the usage of `m!` is likely invalid in statement context
m!();
}

View File

@ -14,6 +14,7 @@
fn foo(p: proc()) { } //~ ERROR `proc` is a reserved keyword
fn bar() { proc() 1; }
fn bar() { proc() 1; } //~ ERROR `proc` is a reserved keyword
//~^ ERROR expected
fn main() { }