diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2015-03-13 11:34:51 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2015-03-13 11:36:30 +0200 |
| commit | 9889aae13e14c306fce8cefd669841fa40f26ee9 (patch) | |
| tree | bbcd59c8ec0c1038956b9b8982f404c52311c4a8 /src/libsyntax/ext | |
| parent | 79dd393a4f144fa5e6f81c720c782de3175810d7 (diff) | |
| download | rust-9889aae13e14c306fce8cefd669841fa40f26ee9.tar.gz rust-9889aae13e14c306fce8cefd669841fa40f26ee9.zip | |
syntax: use lookahead to distinguish inner and outer attributes, instead of passing the latter around.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 19 |
4 files changed, 15 insertions, 25 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 48c045ee4f9..c38556b0782 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -361,8 +361,7 @@ pub mod rt { parse::parse_stmt_from_source_str("<quote expansion>".to_string(), s, self.cfg(), - Vec::new(), - self.parse_sess()) + self.parse_sess()).expect("parse error") } fn parse_expr(&self, s: String) -> P<ast::Expr> { @@ -407,7 +406,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::new(), tts); + let expanded = expand_parse_call(cx, sp, "parse_expr", vec!(), tts); base::MacEager::expr(expanded) } @@ -415,8 +414,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_with_outer_attributes", - vec!(), tts); + let expanded = expand_parse_call(cx, sp, "parse_item", vec!(), tts); base::MacEager::expr(expanded) } @@ -448,9 +446,7 @@ pub fn expand_quote_stmt(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Box<base::MacResult+'static> { - let e_attrs = cx.expr_vec_ng(sp); - let expanded = expand_parse_call(cx, sp, "parse_stmt", - vec!(e_attrs), tts); + let expanded = expand_parse_call(cx, sp, "parse_stmt", vec!(), tts); base::MacEager::expr(expanded) } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index eb0daac3ab8..c61aec0069d 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -115,7 +115,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree -> Option<SmallVector<P<ast::Item>>> { let mut ret = SmallVector::zero(); while self.p.token != token::Eof { - match self.p.parse_item_with_outer_attributes() { + match self.p.parse_item() { Some(item) => ret.push(item), None => self.p.span_fatal( self.p.span, diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index eb15d708232..b7d40a46f3e 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -521,12 +521,15 @@ pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal { // check at the beginning and the parser checks after each bump p.check_unknown_macro_variable(); match name { - "item" => match p.parse_item(Vec::new()) { + "item" => match p.parse_item() { Some(i) => token::NtItem(i), None => p.fatal("expected an item keyword") }, "block" => token::NtBlock(p.parse_block()), - "stmt" => token::NtStmt(p.parse_stmt(Vec::new())), + "stmt" => match p.parse_stmt() { + Some(s) => token::NtStmt(s), + None => p.fatal("expected a statement") + }, "pat" => token::NtPat(p.parse_pat()), "expr" => token::NtExpr(p.parse_expr()), "ty" => token::NtTy(p.parse_ty()), diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 7575d4b5ecd..7a2ae55e914 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -17,7 +17,6 @@ use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; use ext::tt::macro_parser::{parse, parse_or_else}; use parse::lexer::new_tt_reader; use parse::parser::Parser; -use parse::attr::ParserAttr; use parse::token::{self, special_idents, gensym_ident, NtTT, Token}; use parse::token::Token::*; use print; @@ -68,15 +67,8 @@ impl<'a> MacResult for ParserAnyMacro<'a> { } fn make_items(self: Box<ParserAnyMacro<'a>>) -> Option<SmallVector<P<ast::Item>>> { let mut ret = SmallVector::zero(); - loop { - let mut parser = self.parser.borrow_mut(); - // so... do outer attributes attached to the macro invocation - // just disappear? This question applies to make_impl_items, as - // well. - match parser.parse_item_with_outer_attributes() { - Some(item) => ret.push(item), - None => break - } + while let Some(item) = self.parser.borrow_mut().parse_item() { + ret.push(item); } self.ensure_complete_parse(false); Some(ret) @@ -89,7 +81,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> { let mut parser = self.parser.borrow_mut(); match parser.token { token::Eof => break, - _ => ret.push(parser.parse_impl_item_with_outer_attributes()) + _ => ret.push(parser.parse_impl_item()) } } self.ensure_complete_parse(false); @@ -97,10 +89,9 @@ impl<'a> MacResult for ParserAnyMacro<'a> { } fn make_stmt(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Stmt>> { - let attrs = self.parser.borrow_mut().parse_outer_attributes(); - let ret = self.parser.borrow_mut().parse_stmt(attrs); + let ret = self.parser.borrow_mut().parse_stmt(); self.ensure_complete_parse(true); - Some(ret) + ret } } |
