Don't use panicking helpers in Parser.
This commit is contained in:
parent
f7172490f8
commit
1dd87dcfea
9 changed files with 26 additions and 25 deletions
|
@ -79,7 +79,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
cx.span_err(sp, "malformed inline assembly");
|
||||
return DummyResult::expr(sp);
|
||||
}
|
||||
let (s, style) = match expr_to_string(cx, p.parse_expr(),
|
||||
let (s, style) = match expr_to_string(cx, panictry!(p.parse_expr_nopanic()),
|
||||
"inline assembly must be a string literal") {
|
||||
Some((s, st)) => (s, st),
|
||||
// let compilation continue
|
||||
|
@ -102,7 +102,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
let span = p.last_span;
|
||||
|
||||
panictry!(p.expect(&token::OpenDelim(token::Paren)));
|
||||
let out = p.parse_expr();
|
||||
let out = panictry!(p.parse_expr_nopanic());
|
||||
panictry!(p.expect(&token::CloseDelim(token::Paren)));
|
||||
|
||||
// Expands a read+write operand into two operands.
|
||||
|
@ -146,7 +146,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
}
|
||||
|
||||
panictry!(p.expect(&token::OpenDelim(token::Paren)));
|
||||
let input = p.parse_expr();
|
||||
let input = panictry!(p.parse_expr_nopanic());
|
||||
panictry!(p.expect(&token::CloseDelim(token::Paren)));
|
||||
|
||||
inputs.push((constraint, input));
|
||||
|
|
|
@ -809,7 +809,7 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
|
|||
cx.span_err(sp, &format!("{} takes 1 argument", name));
|
||||
return None
|
||||
}
|
||||
let ret = cx.expander().fold_expr(p.parse_expr());
|
||||
let ret = cx.expander().fold_expr(panictry!(p.parse_expr_nopanic()));
|
||||
if p.token != token::Eof {
|
||||
cx.span_err(sp, &format!("{} takes 1 argument", name));
|
||||
}
|
||||
|
@ -826,7 +826,7 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
|
|||
let mut p = cx.new_parser_from_tts(tts);
|
||||
let mut es = Vec::new();
|
||||
while p.token != token::Eof {
|
||||
es.push(cx.expander().fold_expr(p.parse_expr()));
|
||||
es.push(cx.expander().fold_expr(panictry!(p.parse_expr_nopanic())));
|
||||
if panictry!(p.eat(&token::Comma)){
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
ecx.span_err(sp, "requires at least a format string argument");
|
||||
return None;
|
||||
}
|
||||
let fmtstr = p.parse_expr();
|
||||
let fmtstr = panictry!(p.parse_expr_nopanic());
|
||||
let mut named = false;
|
||||
while p.token != token::Eof {
|
||||
if !panictry!(p.eat(&token::Comma)) {
|
||||
|
@ -124,7 +124,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
let name: &str = &ident.name.as_str();
|
||||
|
||||
panictry!(p.expect(&token::Eq));
|
||||
let e = p.parse_expr();
|
||||
let e = panictry!(p.parse_expr_nopanic());
|
||||
match names.get(name) {
|
||||
None => {}
|
||||
Some(prev) => {
|
||||
|
@ -138,7 +138,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
order.push(name.to_string());
|
||||
names.insert(name.to_string(), e);
|
||||
} else {
|
||||
args.push(p.parse_expr());
|
||||
args.push(panictry!(p.parse_expr_nopanic()));
|
||||
}
|
||||
}
|
||||
Some((fmtstr, args, order, names))
|
||||
|
|
|
@ -694,7 +694,7 @@ fn parse_arguments_to_quote(cx: &ExtCtxt, tts: &[ast::TokenTree])
|
|||
let mut p = cx.new_parser_from_tts(tts);
|
||||
p.quote_depth += 1;
|
||||
|
||||
let cx_expr = p.parse_expr();
|
||||
let cx_expr = panictry!(p.parse_expr_nopanic());
|
||||
if !panictry!(p.eat(&token::Comma)) {
|
||||
panic!(p.fatal("expected token `,`"));
|
||||
}
|
||||
|
|
|
@ -109,13 +109,13 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree
|
|||
}
|
||||
impl<'a> base::MacResult for ExpandResult<'a> {
|
||||
fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
|
||||
Some(self.p.parse_expr())
|
||||
Some(panictry!(self.p.parse_expr_nopanic()))
|
||||
}
|
||||
fn make_items(mut self: Box<ExpandResult<'a>>)
|
||||
-> Option<SmallVector<P<ast::Item>>> {
|
||||
let mut ret = SmallVector::zero();
|
||||
while self.p.token != token::Eof {
|
||||
match self.p.parse_item() {
|
||||
match panictry!(self.p.parse_item_nopanic()) {
|
||||
Some(item) => ret.push(item),
|
||||
None => panic!(self.p.span_fatal(
|
||||
self.p.span,
|
||||
|
|
|
@ -503,18 +503,18 @@ pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
|
|||
// check at the beginning and the parser checks after each bump
|
||||
panictry!(p.check_unknown_macro_variable());
|
||||
match name {
|
||||
"item" => match p.parse_item() {
|
||||
"item" => match panictry!(p.parse_item_nopanic()) {
|
||||
Some(i) => token::NtItem(i),
|
||||
None => panic!(p.fatal("expected an item keyword"))
|
||||
},
|
||||
"block" => token::NtBlock(panictry!(p.parse_block())),
|
||||
"stmt" => match p.parse_stmt() {
|
||||
"stmt" => match panictry!(p.parse_stmt_nopanic()) {
|
||||
Some(s) => token::NtStmt(s),
|
||||
None => panic!(p.fatal("expected a statement"))
|
||||
},
|
||||
"pat" => token::NtPat(p.parse_pat()),
|
||||
"expr" => token::NtExpr(p.parse_expr()),
|
||||
"ty" => token::NtTy(p.parse_ty()),
|
||||
"pat" => token::NtPat(panictry!(p.parse_pat_nopanic())),
|
||||
"expr" => token::NtExpr(panictry!(p.parse_expr_nopanic())),
|
||||
"ty" => token::NtTy(panictry!(p.parse_ty_nopanic())),
|
||||
// this could be handled like a token, since it is one
|
||||
"ident" => match p.token {
|
||||
token::Ident(sn,b) => { panictry!(p.bump()); token::NtIdent(Box::new(sn),b) }
|
||||
|
|
|
@ -66,18 +66,18 @@ impl<'a> ParserAnyMacro<'a> {
|
|||
|
||||
impl<'a> MacResult for ParserAnyMacro<'a> {
|
||||
fn make_expr(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Expr>> {
|
||||
let ret = self.parser.borrow_mut().parse_expr();
|
||||
let ret = panictry!(self.parser.borrow_mut().parse_expr_nopanic());
|
||||
self.ensure_complete_parse(true);
|
||||
Some(ret)
|
||||
}
|
||||
fn make_pat(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Pat>> {
|
||||
let ret = self.parser.borrow_mut().parse_pat();
|
||||
let ret = panictry!(self.parser.borrow_mut().parse_pat_nopanic());
|
||||
self.ensure_complete_parse(false);
|
||||
Some(ret)
|
||||
}
|
||||
fn make_items(self: Box<ParserAnyMacro<'a>>) -> Option<SmallVector<P<ast::Item>>> {
|
||||
let mut ret = SmallVector::zero();
|
||||
while let Some(item) = self.parser.borrow_mut().parse_item() {
|
||||
while let Some(item) = panictry!(self.parser.borrow_mut().parse_item_nopanic()) {
|
||||
ret.push(item);
|
||||
}
|
||||
self.ensure_complete_parse(false);
|
||||
|
@ -119,7 +119,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
|
|||
}
|
||||
|
||||
fn make_ty(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Ty>> {
|
||||
let ret = self.parser.borrow_mut().parse_ty();
|
||||
let ret = panictry!(self.parser.borrow_mut().parse_ty_nopanic());
|
||||
self.ensure_complete_parse(true);
|
||||
Some(ret)
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ pub fn parse_expr_from_source_str(name: String,
|
|||
sess: &ParseSess)
|
||||
-> P<ast::Expr> {
|
||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||
maybe_aborted(p.parse_expr(), p)
|
||||
maybe_aborted(panictry!(p.parse_expr_nopanic()), p)
|
||||
}
|
||||
|
||||
pub fn parse_item_from_source_str(name: String,
|
||||
|
@ -125,7 +125,7 @@ pub fn parse_item_from_source_str(name: String,
|
|||
sess: &ParseSess)
|
||||
-> Option<P<ast::Item>> {
|
||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||
maybe_aborted(p.parse_item(),p)
|
||||
maybe_aborted(panictry!(p.parse_item_nopanic()), p)
|
||||
}
|
||||
|
||||
pub fn parse_meta_from_source_str(name: String,
|
||||
|
@ -134,7 +134,7 @@ pub fn parse_meta_from_source_str(name: String,
|
|||
sess: &ParseSess)
|
||||
-> P<ast::MetaItem> {
|
||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||
maybe_aborted(p.parse_meta_item(),p)
|
||||
maybe_aborted(p.parse_meta_item(), p)
|
||||
}
|
||||
|
||||
pub fn parse_stmt_from_source_str(name: String,
|
||||
|
@ -148,7 +148,7 @@ pub fn parse_stmt_from_source_str(name: String,
|
|||
name,
|
||||
source
|
||||
);
|
||||
maybe_aborted(p.parse_stmt(), p)
|
||||
maybe_aborted(panictry!(p.parse_stmt_nopanic()), p)
|
||||
}
|
||||
|
||||
// Warning: This parses with quote_depth > 0, which is not the default.
|
||||
|
|
|
@ -359,7 +359,8 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
// Panicing fns (for now!)
|
||||
// This is so that the quote_*!() syntax extensions
|
||||
// These functions are used by the quote_*!() syntax extensions, but shouldn't
|
||||
// be used otherwise.
|
||||
pub fn parse_expr(&mut self) -> P<Expr> {
|
||||
panictry!(self.parse_expr_nopanic())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue