Parse only outer_attributes for match arms for now

This commit is contained in:
Ville Penttinen 2019-02-17 19:48:08 +02:00
parent 1c97c1ac11
commit 96e3ac389f
3 changed files with 60 additions and 47 deletions

View file

@ -1,15 +1,5 @@
use super::*; use super::*;
/// Parses both inner & outer attributes.
///
/// Allowing to run validation for reporting errors
/// regarding attributes
pub(super) fn all_attributes(p: &mut Parser) {
while p.at(POUND) {
attribute(p, p.nth(1) == EXCL)
}
}
pub(super) fn inner_attributes(p: &mut Parser) { pub(super) fn inner_attributes(p: &mut Parser) {
while p.current() == POUND && p.nth(1) == EXCL { while p.current() == POUND && p.nth(1) == EXCL {
attribute(p, true) attribute(p, true)

View file

@ -331,11 +331,6 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
continue; continue;
} }
// This may result in invalid attributes
// if there are inner attributes mixed in together
// with the outer attributes, but we allow parsing
// those so we can run validation and report better errors
// test match_arms_outer_attributes // test match_arms_outer_attributes
// fn foo() { // fn foo() {
// match () { // match () {
@ -349,7 +344,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
// _ => (), // _ => (),
// } // }
// } // }
attributes::all_attributes(p); attributes::outer_attributes(p);
// test match_arms_commas // test match_arms_commas
// fn foo() { // fn foo() {

View file

@ -33,18 +33,29 @@ SOURCE_FILE@[0; 293)
R_PAREN@[40; 41) R_PAREN@[40; 41)
COMMA@[41; 42) COMMA@[41; 42)
WHITESPACE@[42; 51) WHITESPACE@[42; 51)
err: `Inner attributes are only allowed directly after the opening brace of the match expression` ATTR@[51; 52)
ATTR@[51; 78)
POUND@[51; 52) POUND@[51; 52)
EXCL@[52; 53) err: `expected `[``
TOKEN_TREE@[53; 78) err: `expected pattern`
MATCH_ARM@[52; 78)
ERROR@[52; 53)
EXCL@[52; 53)
err: `expected FAT_ARROW`
ARRAY_EXPR@[53; 78)
L_BRACK@[53; 54) L_BRACK@[53; 54)
IDENT@[54; 57) "doc" CALL_EXPR@[54; 77)
TOKEN_TREE@[57; 77) PATH_EXPR@[54; 57)
L_PAREN@[57; 58) PATH@[54; 57)
STRING@[58; 76) PATH_SEGMENT@[54; 57)
R_PAREN@[76; 77) NAME_REF@[54; 57)
IDENT@[54; 57) "doc"
ARG_LIST@[57; 77)
L_PAREN@[57; 58)
LITERAL@[58; 76)
STRING@[58; 76)
R_PAREN@[76; 77)
R_BRACK@[77; 78) R_BRACK@[77; 78)
err: `expected COMMA`
WHITESPACE@[78; 87) WHITESPACE@[78; 87)
MATCH_ARM@[87; 94) MATCH_ARM@[87; 94)
PLACEHOLDER_PAT@[87; 88) PLACEHOLDER_PAT@[87; 88)
@ -92,23 +103,29 @@ SOURCE_FILE@[0; 293)
R_PAREN@[149; 150) R_PAREN@[149; 150)
COMMA@[150; 151) COMMA@[150; 151)
WHITESPACE@[151; 160) WHITESPACE@[151; 160)
err: `Inner attributes are only allowed directly after the opening brace of the match expression` ATTR@[160; 161)
ATTR@[160; 179)
POUND@[160; 161) POUND@[160; 161)
EXCL@[161; 162) err: `expected `[``
TOKEN_TREE@[162; 179) err: `expected pattern`
MATCH_ARM@[161; 179)
ERROR@[161; 162)
EXCL@[161; 162)
err: `expected FAT_ARROW`
ARRAY_EXPR@[162; 179)
L_BRACK@[162; 163) L_BRACK@[162; 163)
IDENT@[163; 166) "doc" CALL_EXPR@[163; 178)
TOKEN_TREE@[166; 178) PATH_EXPR@[163; 166)
L_PAREN@[166; 167) PATH@[163; 166)
STRING@[167; 177) PATH_SEGMENT@[163; 166)
R_PAREN@[177; 178) NAME_REF@[163; 166)
IDENT@[163; 166) "doc"
ARG_LIST@[166; 178)
L_PAREN@[166; 167)
LITERAL@[167; 177)
STRING@[167; 177)
R_PAREN@[177; 178)
R_BRACK@[178; 179) R_BRACK@[178; 179)
WHITESPACE@[179; 184) WHITESPACE@[179; 184)
err: `expected pattern`
err: `expected FAT_ARROW`
err: `expected expression`
MATCH_ARM@[184; 184)
R_CURLY@[184; 185) R_CURLY@[184; 185)
WHITESPACE@[185; 191) WHITESPACE@[185; 191)
MATCH_EXPR@[191; 290) MATCH_EXPR@[191; 290)
@ -132,18 +149,29 @@ SOURCE_FILE@[0; 293)
R_PAREN@[220; 221) R_PAREN@[220; 221)
R_BRACK@[221; 222) R_BRACK@[221; 222)
WHITESPACE@[222; 231) WHITESPACE@[222; 231)
err: `Inner attributes are only allowed directly after the opening brace of the match expression` ATTR@[231; 232)
ATTR@[231; 250)
POUND@[231; 232) POUND@[231; 232)
EXCL@[232; 233) err: `expected `[``
TOKEN_TREE@[233; 250) err: `expected pattern`
MATCH_ARM@[232; 250)
ERROR@[232; 233)
EXCL@[232; 233)
err: `expected FAT_ARROW`
ARRAY_EXPR@[233; 250)
L_BRACK@[233; 234) L_BRACK@[233; 234)
IDENT@[234; 237) "doc" CALL_EXPR@[234; 249)
TOKEN_TREE@[237; 249) PATH_EXPR@[234; 237)
L_PAREN@[237; 238) PATH@[234; 237)
STRING@[238; 248) PATH_SEGMENT@[234; 237)
R_PAREN@[248; 249) NAME_REF@[234; 237)
IDENT@[234; 237) "doc"
ARG_LIST@[237; 249)
L_PAREN@[237; 238)
LITERAL@[238; 248)
STRING@[238; 248)
R_PAREN@[248; 249)
R_BRACK@[249; 250) R_BRACK@[249; 250)
err: `expected COMMA`
WHITESPACE@[250; 259) WHITESPACE@[250; 259)
MATCH_ARM@[259; 266) MATCH_ARM@[259; 266)
PLACEHOLDER_PAT@[259; 260) PLACEHOLDER_PAT@[259; 260)