]> git.lizzy.rs Git - rust.git/commitdiff
Make quote plugin use parsing functions which explicitly panic.
authorEli Friedman <eli.friedman@gmail.com>
Wed, 28 Oct 2015 05:20:01 +0000 (22:20 -0700)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 28 Oct 2015 21:11:31 +0000 (14:11 -0700)
Rename parse_* to parse_*_panic, and add parse_attribute_panic.

src/libsyntax/ext/quote.rs
src/libsyntax/parse/attr.rs
src/libsyntax/parse/parser.rs
src/test/auxiliary/macro_crate_test.rs

index 1e337c29f2b6875b788ff07b49243126e1d2d4c5..59e8533a83d3198117db470f68ca6545a5dc71c5 100644 (file)
@@ -327,7 +327,7 @@ pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt,
                               sp: Span,
                               tts: &[ast::TokenTree])
                               -> Box<base::MacResult+'cx> {
-    let expanded = expand_parse_call(cx, sp, "parse_expr", vec!(), tts);
+    let expanded = expand_parse_call(cx, sp, "parse_expr_panic", vec!(), tts);
     base::MacEager::expr(expanded)
 }
 
@@ -335,7 +335,7 @@ pub fn expand_quote_item<'cx>(cx: &mut ExtCtxt,
                               sp: Span,
                               tts: &[ast::TokenTree])
                               -> Box<base::MacResult+'cx> {
-    let expanded = expand_parse_call(cx, sp, "parse_item", vec!(), tts);
+    let expanded = expand_parse_call(cx, sp, "parse_item_panic", vec!(), tts);
     base::MacEager::expr(expanded)
 }
 
@@ -343,7 +343,7 @@ pub fn expand_quote_pat<'cx>(cx: &'cx mut ExtCtxt,
                              sp: Span,
                              tts: &[ast::TokenTree])
                              -> Box<base::MacResult+'cx> {
-    let expanded = expand_parse_call(cx, sp, "parse_pat", vec!(), tts);
+    let expanded = expand_parse_call(cx, sp, "parse_pat_panic", vec!(), tts);
     base::MacEager::expr(expanded)
 }
 
@@ -351,7 +351,7 @@ pub fn expand_quote_arm(cx: &mut ExtCtxt,
                         sp: Span,
                         tts: &[ast::TokenTree])
                         -> Box<base::MacResult+'static> {
-    let expanded = expand_parse_call(cx, sp, "parse_arm", vec!(), tts);
+    let expanded = expand_parse_call(cx, sp, "parse_arm_panic", vec!(), tts);
     base::MacEager::expr(expanded)
 }
 
@@ -359,7 +359,7 @@ pub fn expand_quote_ty(cx: &mut ExtCtxt,
                        sp: Span,
                        tts: &[ast::TokenTree])
                        -> Box<base::MacResult+'static> {
-    let expanded = expand_parse_call(cx, sp, "parse_ty", vec!(), tts);
+    let expanded = expand_parse_call(cx, sp, "parse_ty_panic", vec!(), tts);
     base::MacEager::expr(expanded)
 }
 
@@ -367,7 +367,7 @@ pub fn expand_quote_stmt(cx: &mut ExtCtxt,
                          sp: Span,
                          tts: &[ast::TokenTree])
                          -> Box<base::MacResult+'static> {
-    let expanded = expand_parse_call(cx, sp, "parse_stmt", vec!(), tts);
+    let expanded = expand_parse_call(cx, sp, "parse_stmt_panic", vec!(), tts);
     base::MacEager::expr(expanded)
 }
 
@@ -375,7 +375,7 @@ pub fn expand_quote_attr(cx: &mut ExtCtxt,
                          sp: Span,
                          tts: &[ast::TokenTree])
                          -> Box<base::MacResult+'static> {
-    let expanded = expand_parse_call(cx, sp, "parse_attribute",
+    let expanded = expand_parse_call(cx, sp, "parse_attribute_panic",
                                     vec!(cx.expr_bool(sp, true)), tts);
 
     base::MacEager::expr(expanded)
index 7b96135f1c3e1cbbddeb30ee751bc345ae7adec5..5df2478d4875809c8fe5c6e381ba44658952913f 100644 (file)
@@ -51,7 +51,7 @@ pub fn parse_outer_attributes(&mut self) -> PResult<Vec<ast::Attribute>> {
     ///
     /// If permit_inner is true, then a leading `!` indicates an inner
     /// attribute
-    fn parse_attribute(&mut self, permit_inner: bool) -> PResult<ast::Attribute> {
+    pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<ast::Attribute> {
         debug!("parse_attributes: permit_inner={:?} self.token={:?}",
                permit_inner, self.token);
         let (span, value, mut style) = match self.token {
index d71ea4d105b3bc1cef7250f1f266e0e527832e65..570934a5bff68bc736699233cb7a243016f27661 100644 (file)
@@ -360,30 +360,34 @@ pub fn new(sess: &'a ParseSess,
     // Panicing fns (for now!)
     // These functions are used by the quote_*!() syntax extensions, but shouldn't
     // be used otherwise.
-    pub fn parse_expr(&mut self) -> P<Expr> {
+    pub fn parse_expr_panic(&mut self) -> P<Expr> {
         panictry!(self.parse_expr_nopanic())
     }
 
-    pub fn parse_item(&mut self) -> Option<P<Item>> {
+    pub fn parse_item_panic(&mut self) -> Option<P<Item>> {
         panictry!(self.parse_item_nopanic())
     }
 
-    pub fn parse_pat(&mut self) -> P<Pat> {
+    pub fn parse_pat_panic(&mut self) -> P<Pat> {
         panictry!(self.parse_pat_nopanic())
     }
 
-    pub fn parse_arm(&mut self) -> Arm {
+    pub fn parse_arm_panic(&mut self) -> Arm {
         panictry!(self.parse_arm_nopanic())
     }
 
-    pub fn parse_ty(&mut self) -> P<Ty> {
+    pub fn parse_ty_panic(&mut self) -> P<Ty> {
         panictry!(self.parse_ty_nopanic())
     }
 
-    pub fn parse_stmt(&mut self) -> Option<P<Stmt>> {
+    pub fn parse_stmt_panic(&mut self) -> Option<P<Stmt>> {
         panictry!(self.parse_stmt_nopanic())
     }
 
+    pub fn parse_attribute_panic(&mut self, permit_inner: bool) -> ast::Attribute {
+        panictry!(self.parse_attribute(permit_inner))
+    }
+
     /// Convert a token to a string using self's reader
     pub fn token_to_string(token: &token::Token) -> String {
         pprust::token_to_string(token)
index 77f0e0f2c3411ecbe827d1809b7c65486ff85439..0bb5c05aaf5bac88280fe41f9a2e19446db50ed6 100644 (file)
@@ -54,7 +54,7 @@ fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree])
     // Parse an expression and emit it unchanged.
     let mut parser = parse::new_parser_from_tts(cx.parse_sess(),
         cx.cfg(), tts.to_vec());
-    let expr = parser.parse_expr();
+    let expr = parser.parse_expr_panic();
     MacEager::expr(quote_expr!(&mut *cx, $expr))
 }