From 71efdaa6364142b359c59659ec10f35a1e53b5d2 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 30 Sep 2019 04:44:33 +0800 Subject: Parse correct AttrInput --- crates/ra_parser/src/grammar/attributes.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'crates/ra_parser/src') diff --git a/crates/ra_parser/src/grammar/attributes.rs b/crates/ra_parser/src/grammar/attributes.rs index 1cfd301b5..72e7717b7 100644 --- a/crates/ra_parser/src/grammar/attributes.rs +++ b/crates/ra_parser/src/grammar/attributes.rs @@ -22,8 +22,25 @@ fn attribute(p: &mut Parser, inner: bool) { p.bump(T![!]); } - if p.at(T!['[']) { - items::token_tree(p); + if p.eat(T!['[']) { + paths::use_path(p); + + let is_delimiter = |p: &mut Parser| match p.current() { + T!['('] | T!['['] | T!['{'] => true, + _ => false, + }; + + if p.eat(T![=]) { + if expressions::literal(p).is_none() { + p.error("expected literal"); + } + } else if is_delimiter(p) { + items::token_tree(p); + } + + if !p.eat(T![']']) { + p.error("expected `]`"); + } } else { p.error("expected `[`"); } -- cgit v1.2.3 From f7e12559cb26b59a9a2ecee4deecaf6fe9100d16 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 30 Sep 2019 16:09:02 +0800 Subject: Fixes --- crates/ra_parser/src/grammar/attributes.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'crates/ra_parser/src') diff --git a/crates/ra_parser/src/grammar/attributes.rs b/crates/ra_parser/src/grammar/attributes.rs index 72e7717b7..63ca9ca32 100644 --- a/crates/ra_parser/src/grammar/attributes.rs +++ b/crates/ra_parser/src/grammar/attributes.rs @@ -25,17 +25,15 @@ fn attribute(p: &mut Parser, inner: bool) { if p.eat(T!['[']) { paths::use_path(p); - let is_delimiter = |p: &mut Parser| match p.current() { - T!['('] | T!['['] | T!['{'] => true, - _ => false, - }; - - if p.eat(T![=]) { - if expressions::literal(p).is_none() { - p.error("expected literal"); + match p.current() { + T![=] => { + p.bump(T![=]); + if expressions::literal(p).is_none() { + p.error("expected literal"); + } } - } else if is_delimiter(p) { - items::token_tree(p); + T!['('] | T!['['] | T!['{'] => items::token_tree(p), + _ => {} } if !p.eat(T![']']) { -- cgit v1.2.3