Make attrs be a child of the let statement

This commit is contained in:
DJMcNab 2019-01-26 22:02:23 +00:00
parent 55a3e21ac4
commit 7055d43c3a
3 changed files with 26 additions and 23 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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)