about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-08-18 08:17:45 +0000
committerbors <bors@rust-lang.org>2017-08-18 08:17:45 +0000
commite6ab51165a1b67409c1ee1efeaf0cd139dc6c592 (patch)
tree171566dee7bf0879f42eb6b97335d85fe23026d7 /src/libsyntax/parse
parent8016eea9dc8c6c4a56310ecf9c28f4a389e06ac3 (diff)
parent0bfe4178af1c82a7907c3408e3fe910f47948bf5 (diff)
downloadrust-e6ab51165a1b67409c1ee1efeaf0cd139dc6c592.tar.gz
rust-e6ab51165a1b67409c1ee1efeaf0cd139dc6c592.zip
Auto merge of #43904 - topecongiro:libsyntax/parse-attr, r=petrochenkov
Eat open paren when parsing list in libsyntax/parse/attr.rs

This PR adds a small refactoring:
```diff
      pub fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {
         Ok(if self.eat(&token::Eq) {
             ast::MetaItemKind::NameValue(self.parse_unsuffixed_lit()?)
-        } else if self.token == token::OpenDelim(token::Paren) {
+        } else if self.eat(&token::OpenDelim(token::Paren)) {
             ast::MetaItemKind::List(self.parse_meta_seq()?)
         } else {
-            self.eat(&token::OpenDelim(token::Paren));
             ast::MetaItemKind::Word
         })
     }
```
in `parse_meta_item_kind()`, the parser calls `self.eat(&token::OpenDelim(token::Paren));` before returning `ast::MetaItemKind::Word` just to add `(` to expected token. It seems more natural to eat the paren when parsing `ast::MetaItemKind::List`.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/attr.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs
index 5dc5a53e279..48c92873e14 100644
--- a/src/libsyntax/parse/attr.rs
+++ b/src/libsyntax/parse/attr.rs
@@ -244,10 +244,9 @@ impl<'a> Parser<'a> {
     pub fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {
         Ok(if self.eat(&token::Eq) {
             ast::MetaItemKind::NameValue(self.parse_unsuffixed_lit()?)
-        } else if self.token == token::OpenDelim(token::Paren) {
+        } else if self.eat(&token::OpenDelim(token::Paren)) {
             ast::MetaItemKind::List(self.parse_meta_seq()?)
         } else {
-            self.eat(&token::OpenDelim(token::Paren));
             ast::MetaItemKind::Word
         })
     }
@@ -277,9 +276,8 @@ impl<'a> Parser<'a> {
 
     /// matches meta_seq = ( COMMASEP(meta_item_inner) )
     fn parse_meta_seq(&mut self) -> PResult<'a, Vec<ast::NestedMetaItem>> {
-        self.parse_unspanned_seq(&token::OpenDelim(token::Paren),
-                                 &token::CloseDelim(token::Paren),
-                                 SeqSep::trailing_allowed(token::Comma),
-                                 |p: &mut Parser<'a>| p.parse_meta_item_inner())
+        self.parse_seq_to_end(&token::CloseDelim(token::Paren),
+                              SeqSep::trailing_allowed(token::Comma),
+                              |p: &mut Parser<'a>| p.parse_meta_item_inner())
     }
 }