From 7055d43c3a1edca16cf5625f1b908643fa0bf21a Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 26 Jan 2019 22:02:23 +0000 Subject: [PATCH] Make attrs be a child of the let statement --- crates/ra_syntax/src/grammar/expressions.rs | 15 +++++---- crates/ra_syntax/src/grammar/items.rs | 2 +- .../tests/data/parser/ok/0044_let_attrs.txt | 32 +++++++++---------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index 0b2f7b11695..8dd9587d013 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs @@ -45,7 +45,10 @@ pub(crate) fn block(p: &mut Parser) { while !p.at(EOF) && !p.at(R_CURLY) { match p.current() { - LET_KW => let_stmt(p), + LET_KW => { + let m = p.start(); + let_stmt(p, m) + } // test nocontentexpr // fn foo(){ // ;;;some_expr();;;;{;;;};;;;Ok(()) @@ -54,8 +57,9 @@ pub(crate) fn block(p: &mut Parser) { _ => { // test block_items // fn a() { fn b() {} } - let has_attrs = p.at(POUND); let m = p.start(); + let has_attrs = p.at(POUND); + attributes::outer_attributes(p); match items::maybe_item(p, items::ItemFlavor::Mod) { items::MaybeItem::Item(kind) => { m.complete(p, kind); @@ -68,10 +72,10 @@ pub(crate) fn block(p: &mut Parser) { // fn foo() { pub 92; } //FIXME items::MaybeItem::None => { if has_attrs { - m.abandon(p); if p.at(LET_KW) { - let_stmt(p); + let_stmt(p, m); } else { + m.abandon(p); p.error("expected a let statement"); } } else { @@ -116,9 +120,8 @@ pub(crate) fn block(p: &mut Parser) { // let c = 92; // let d: i32 = 92; // } - fn let_stmt(p: &mut Parser) { + fn let_stmt(p: &mut Parser, m: Marker) { assert!(p.at(LET_KW)); - let m = p.start(); p.bump(); patterns::pattern(p); if p.at(COLON) { diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs index 265e84570d5..18039cd3f8d 100644 --- a/crates/ra_syntax/src/grammar/items.rs +++ b/crates/ra_syntax/src/grammar/items.rs @@ -36,6 +36,7 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { let m = p.start(); + attributes::outer_attributes(p); match maybe_item(p, flavor) { MaybeItem::Item(kind) => { m.complete(p, kind); @@ -79,7 +80,6 @@ pub(super) enum MaybeItem { } pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem { - attributes::outer_attributes(p); opt_visibility(p); if let Some(kind) = items_without_modifiers(p) { return MaybeItem::Item(kind); diff --git a/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt b/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt index b3f37dd96fc..1f52f699b3f 100644 --- a/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt +++ b/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt @@ -13,22 +13,22 @@ SOURCE_FILE@[0; 166) BLOCK@[71; 165) L_CURLY@[71; 72) WHITESPACE@[72; 77) - ATTR@[77; 106) - POUND@[77; 78) - TOKEN_TREE@[78; 106) - L_BRACK@[78; 79) - IDENT@[79; 82) "cfg" - TOKEN_TREE@[82; 105) - L_PAREN@[82; 83) - IDENT@[83; 90) "feature" - WHITESPACE@[90; 91) - EQ@[91; 92) - WHITESPACE@[92; 93) - STRING@[93; 104) - R_PAREN@[104; 105) - R_BRACK@[105; 106) - WHITESPACE@[106; 111) - LET_STMT@[111; 163) + LET_STMT@[77; 163) + ATTR@[77; 106) + POUND@[77; 78) + TOKEN_TREE@[78; 106) + L_BRACK@[78; 79) + IDENT@[79; 82) "cfg" + TOKEN_TREE@[82; 105) + L_PAREN@[82; 83) + IDENT@[83; 90) "feature" + WHITESPACE@[90; 91) + EQ@[91; 92) + WHITESPACE@[92; 93) + STRING@[93; 104) + R_PAREN@[104; 105) + R_BRACK@[105; 106) + WHITESPACE@[106; 111) LET_KW@[111; 114) WHITESPACE@[114; 115) BIND_PAT@[115; 124)