From b7c45fba57224a013fbc926abd2e8e9f8f3c77d4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Jan 2020 11:44:40 +0100 Subject: Extract expr_with_attrs --- crates/ra_parser/src/grammar/expressions.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crates/ra_parser/src/grammar/expressions.rs') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index a31a7a08d..3cf619e38 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -19,6 +19,26 @@ pub(super) fn expr(p: &mut Parser) -> (Option, BlockLike) { expr_bp(p, r, 1) } +pub(super) fn expr_with_attrs(p: &mut Parser) -> bool { + let m = p.start(); + let has_attrs = p.at(T![#]); + attributes::outer_attributes(p); + + let (cm, _block_like) = expr(p); + let success = cm.is_some(); + + match (has_attrs, cm) { + (true, Some(cm)) => { + let kind = cm.kind(); + cm.undo_completion(p).abandon(p); + m.complete(p, kind); + } + _ => m.abandon(p), + } + + success +} + pub(super) fn expr_stmt(p: &mut Parser) -> (Option, BlockLike) { let r = Restrictions { forbid_structs: false, prefer_stmt: true }; expr_bp(p, r, 1) -- cgit v1.2.3 From 3a859e587f3bcf9f49293bd1f2b2d19cdfd2be4b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Jan 2020 11:47:07 +0100 Subject: Nest attrs into exprs in function args --- crates/ra_parser/src/grammar/expressions.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'crates/ra_parser/src/grammar/expressions.rs') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 3cf619e38..06c92645e 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -564,12 +564,9 @@ fn arg_list(p: &mut Parser) { // fn main() { // foo(#[attr] 92) // } - attributes::outer_attributes(p); - if !p.at_ts(EXPR_FIRST) { - p.error("expected expression"); + if !expr_with_attrs(p) { break; } - expr(p); if !p.at(T![')']) && !p.expect(T![,]) { break; } -- cgit v1.2.3