Extract expr_with_attrs

This commit is contained in:
Aleksey Kladov 2020-01-17 11:44:40 +01:00
parent 90b8a31b83
commit b7c45fba57
3 changed files with 36 additions and 23 deletions

View File

@ -19,6 +19,26 @@ pub(super) fn expr(p: &mut Parser) -> (Option<CompletedMarker>, 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<CompletedMarker>, BlockLike) {
let r = Restrictions { forbid_structs: false, prefer_stmt: true };
expr_bp(p, r, 1)

View File

@ -191,19 +191,8 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
// test array_attrs
// const A: &[i64] = &[1, #[cfg(test)] 2];
let m = p.start();
let has_attrs = p.at(T![#]);
attributes::outer_attributes(p);
let cm = expr(p).0;
match (has_attrs, cm) {
(true, Some(cm)) => {
let kind = cm.kind();
cm.undo_completion(p).abandon(p);
m.complete(p, kind);
}
_ => m.abandon(p),
if !expr_with_attrs(p) {
break;
}
if n_exprs == 1 && p.eat(T![;]) {

View File

@ -12,8 +12,8 @@ SOURCE_FILE@[0; 112)
BLOCK@[7; 33)
L_CURLY@[7; 8) "{"
WHITESPACE@[8; 9) " "
EXPR_STMT@[9; 26)
ARRAY_EXPR@[9; 26)
EXPR_STMT@[9; 17)
ARRAY_EXPR@[9; 17)
L_BRACK@[9; 10) "["
LITERAL@[10; 11)
INT_NUMBER@[10; 11) "1"
@ -25,10 +25,13 @@ SOURCE_FILE@[0; 112)
WHITESPACE@[15; 16) " "
ERROR@[16; 17)
AT@[16; 17) "@"
EXPR_STMT@[17; 18)
ERROR@[17; 18)
COMMA@[17; 18) ","
WHITESPACE@[18; 19) " "
ERROR@[19; 25)
STRUCT_KW@[19; 25) "struct"
WHITESPACE@[18; 19) " "
STRUCT_DEF@[19; 26)
STRUCT_KW@[19; 25) "struct"
ERROR@[25; 26)
COMMA@[25; 26) ","
WHITESPACE@[26; 27) " "
LET_STMT@[27; 31)
@ -148,11 +151,12 @@ SOURCE_FILE@[0; 112)
R_CURLY@[110; 111) "}"
WHITESPACE@[111; 112) "\n"
error 16: expected expression
error 19: expected expression
error 26: expected expression
error 26: expected COMMA
error 26: expected R_BRACK
error 26: expected SEMI
error 17: expected R_BRACK
error 17: expected SEMI
error 17: expected expression
error 18: expected SEMI
error 25: expected a name
error 26: expected `;`, `{`, or `(`
error 30: expected pattern
error 31: expected SEMI
error 52: expected expression