mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
expr stmt
This commit is contained in:
parent
66182ed5d5
commit
9e02e432b5
5 changed files with 111 additions and 1 deletions
|
@ -146,7 +146,9 @@ Grammar(
|
|||
"NAME_REF",
|
||||
"VALUE_PARAMETER",
|
||||
"BLOCK",
|
||||
|
||||
"LET_STMT",
|
||||
"EXPR_STMT",
|
||||
|
||||
"TYPE_PARAM",
|
||||
"LIFETIME_PARAM",
|
||||
|
|
|
@ -223,6 +223,11 @@ fn fn_item(p: &mut Parser) {
|
|||
fn_ret_type(p);
|
||||
block(p);
|
||||
|
||||
// test block
|
||||
// fn a() {}
|
||||
// fn b() { let _ = 1; }
|
||||
// fn c() { 1; 2; }
|
||||
// fn d() { 1; 2 }
|
||||
fn block(p: &mut Parser) {
|
||||
if !p.at(L_CURLY) {
|
||||
p.error("expected block");
|
||||
|
@ -232,7 +237,18 @@ fn fn_item(p: &mut Parser) {
|
|||
while !p.at(EOF) && !p.at(R_CURLY) {
|
||||
match p.current() {
|
||||
LET_KW => let_stmt(p),
|
||||
_ => p.err_and_bump("expected statement"),
|
||||
_ => {
|
||||
let expr_stmt = p.start();
|
||||
expressions::expr(p);
|
||||
if p.eat(SEMI) {
|
||||
expr_stmt.complete(p, EXPR_STMT);
|
||||
if p.at(R_CURLY) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
expr_stmt.abandon(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
p.expect(R_CURLY);
|
||||
|
|
|
@ -137,6 +137,7 @@ pub enum SyntaxKind {
|
|||
VALUE_PARAMETER,
|
||||
BLOCK,
|
||||
LET_STMT,
|
||||
EXPR_STMT,
|
||||
TYPE_PARAM,
|
||||
LIFETIME_PARAM,
|
||||
TYPE_PARAM_LIST,
|
||||
|
@ -287,6 +288,7 @@ impl SyntaxKind {
|
|||
VALUE_PARAMETER => &SyntaxInfo { name: "VALUE_PARAMETER" },
|
||||
BLOCK => &SyntaxInfo { name: "BLOCK" },
|
||||
LET_STMT => &SyntaxInfo { name: "LET_STMT" },
|
||||
EXPR_STMT => &SyntaxInfo { name: "EXPR_STMT" },
|
||||
TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" },
|
||||
LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" },
|
||||
TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" },
|
||||
|
|
4
tests/data/parser/inline/0045_block.rs
Normal file
4
tests/data/parser/inline/0045_block.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
fn a() {}
|
||||
fn b() { let _ = 1; }
|
||||
fn c() { 1; 2; }
|
||||
fn d() { 1; 2 }
|
86
tests/data/parser/inline/0045_block.txt
Normal file
86
tests/data/parser/inline/0045_block.txt
Normal file
|
@ -0,0 +1,86 @@
|
|||
FILE@[0; 65)
|
||||
FN_ITEM@[0; 10)
|
||||
FN_KW@[0; 2)
|
||||
NAME@[2; 4)
|
||||
WHITESPACE@[2; 3)
|
||||
IDENT@[3; 4) "a"
|
||||
PARAM_LIST@[4; 7)
|
||||
L_PAREN@[4; 5)
|
||||
R_PAREN@[5; 6)
|
||||
WHITESPACE@[6; 7)
|
||||
BLOCK@[7; 10)
|
||||
L_CURLY@[7; 8)
|
||||
R_CURLY@[8; 9)
|
||||
WHITESPACE@[9; 10)
|
||||
FN_ITEM@[10; 32)
|
||||
FN_KW@[10; 12)
|
||||
NAME@[12; 14)
|
||||
WHITESPACE@[12; 13)
|
||||
IDENT@[13; 14) "b"
|
||||
PARAM_LIST@[14; 17)
|
||||
L_PAREN@[14; 15)
|
||||
R_PAREN@[15; 16)
|
||||
WHITESPACE@[16; 17)
|
||||
BLOCK@[17; 32)
|
||||
L_CURLY@[17; 18)
|
||||
LET_STMT@[18; 30)
|
||||
WHITESPACE@[18; 19)
|
||||
LET_KW@[19; 22)
|
||||
PLACEHOLDER_PAT@[22; 25)
|
||||
WHITESPACE@[22; 23)
|
||||
UNDERSCORE@[23; 24)
|
||||
WHITESPACE@[24; 25)
|
||||
EQ@[25; 26)
|
||||
LITERAL@[26; 28)
|
||||
WHITESPACE@[26; 27)
|
||||
INT_NUMBER@[27; 28)
|
||||
SEMI@[28; 29)
|
||||
WHITESPACE@[29; 30)
|
||||
R_CURLY@[30; 31)
|
||||
WHITESPACE@[31; 32)
|
||||
FN_ITEM@[32; 49)
|
||||
FN_KW@[32; 34)
|
||||
NAME@[34; 36)
|
||||
WHITESPACE@[34; 35)
|
||||
IDENT@[35; 36) "c"
|
||||
PARAM_LIST@[36; 39)
|
||||
L_PAREN@[36; 37)
|
||||
R_PAREN@[37; 38)
|
||||
WHITESPACE@[38; 39)
|
||||
BLOCK@[39; 49)
|
||||
L_CURLY@[39; 40)
|
||||
EXPR_STMT@[40; 44)
|
||||
LITERAL@[40; 42)
|
||||
WHITESPACE@[40; 41)
|
||||
INT_NUMBER@[41; 42)
|
||||
SEMI@[42; 43)
|
||||
WHITESPACE@[43; 44)
|
||||
EXPR_STMT@[44; 47)
|
||||
LITERAL@[44; 45)
|
||||
INT_NUMBER@[44; 45)
|
||||
SEMI@[45; 46)
|
||||
WHITESPACE@[46; 47)
|
||||
R_CURLY@[47; 48)
|
||||
WHITESPACE@[48; 49)
|
||||
FN_ITEM@[49; 65)
|
||||
FN_KW@[49; 51)
|
||||
NAME@[51; 53)
|
||||
WHITESPACE@[51; 52)
|
||||
IDENT@[52; 53) "d"
|
||||
PARAM_LIST@[53; 56)
|
||||
L_PAREN@[53; 54)
|
||||
R_PAREN@[54; 55)
|
||||
WHITESPACE@[55; 56)
|
||||
BLOCK@[56; 65)
|
||||
L_CURLY@[56; 57)
|
||||
EXPR_STMT@[57; 61)
|
||||
LITERAL@[57; 59)
|
||||
WHITESPACE@[57; 58)
|
||||
INT_NUMBER@[58; 59)
|
||||
SEMI@[59; 60)
|
||||
WHITESPACE@[60; 61)
|
||||
LITERAL@[61; 63)
|
||||
INT_NUMBER@[61; 62)
|
||||
WHITESPACE@[62; 63)
|
||||
R_CURLY@[63; 64)
|
||||
WHITESPACE@[64; 65)
|
Loading…
Reference in a new issue