mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 03:03:40 +00:00
add await to syntax, parser for await_expr
This commit is contained in:
parent
e18f8495d6
commit
3a7f07c62d
@ -393,6 +393,18 @@ fn postfix_expr(
|
||||
T![.] if p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth(2) == T![::]) => {
|
||||
method_call_expr(p, lhs)
|
||||
}
|
||||
T![.] if p.nth(1) == AWAIT_KW => {
|
||||
// test await_expr
|
||||
// fn foo() {
|
||||
// x.await;
|
||||
// x.0.await;
|
||||
// x.0().await?.hello();
|
||||
// }
|
||||
let m = lhs.precede(p);
|
||||
p.bump();
|
||||
p.bump();
|
||||
m.complete(p, AWAIT_EXPR)
|
||||
}
|
||||
T![.] => field_expr(p, lhs),
|
||||
// test postfix_range
|
||||
// fn foo() { let x = 1..; }
|
||||
|
@ -105,6 +105,7 @@ pub enum SyntaxKind {
|
||||
RETURN_KW,
|
||||
TRY_KW,
|
||||
BOX_KW,
|
||||
AWAIT_KW,
|
||||
AUTO_KW,
|
||||
DEFAULT_KW,
|
||||
EXISTENTIAL_KW,
|
||||
@ -193,6 +194,7 @@ pub enum SyntaxKind {
|
||||
INDEX_EXPR,
|
||||
METHOD_CALL_EXPR,
|
||||
FIELD_EXPR,
|
||||
AWAIT_EXPR,
|
||||
TRY_EXPR,
|
||||
CAST_EXPR,
|
||||
REF_EXPR,
|
||||
@ -338,6 +340,7 @@ macro_rules! T {
|
||||
(return) => { $crate::SyntaxKind::RETURN_KW };
|
||||
(try) => { $crate::SyntaxKind::TRY_KW };
|
||||
(box) => { $crate::SyntaxKind::BOX_KW };
|
||||
(await) => { $crate::SyntaxKind::AWAIT_KW };
|
||||
(auto) => { $crate::SyntaxKind::AUTO_KW };
|
||||
(default) => { $crate::SyntaxKind::DEFAULT_KW };
|
||||
(existential) => { $crate::SyntaxKind::EXISTENTIAL_KW };
|
||||
@ -398,6 +401,7 @@ impl SyntaxKind {
|
||||
| RETURN_KW
|
||||
| TRY_KW
|
||||
| BOX_KW
|
||||
| AWAIT_KW
|
||||
| AUTO_KW
|
||||
| DEFAULT_KW
|
||||
| EXISTENTIAL_KW
|
||||
@ -572,6 +576,7 @@ impl SyntaxKind {
|
||||
RETURN_KW => &SyntaxInfo { name: "RETURN_KW" },
|
||||
TRY_KW => &SyntaxInfo { name: "TRY_KW" },
|
||||
BOX_KW => &SyntaxInfo { name: "BOX_KW" },
|
||||
AWAIT_KW => &SyntaxInfo { name: "AWAIT_KW" },
|
||||
AUTO_KW => &SyntaxInfo { name: "AUTO_KW" },
|
||||
DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" },
|
||||
EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" },
|
||||
@ -660,6 +665,7 @@ impl SyntaxKind {
|
||||
INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" },
|
||||
METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" },
|
||||
FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" },
|
||||
AWAIT_EXPR => &SyntaxInfo { name: "AWAIT_EXPR" },
|
||||
TRY_EXPR => &SyntaxInfo { name: "TRY_EXPR" },
|
||||
CAST_EXPR => &SyntaxInfo { name: "CAST_EXPR" },
|
||||
REF_EXPR => &SyntaxInfo { name: "REF_EXPR" },
|
||||
@ -752,6 +758,7 @@ impl SyntaxKind {
|
||||
"return" => RETURN_KW,
|
||||
"try" => TRY_KW,
|
||||
"box" => BOX_KW,
|
||||
"await" => AWAIT_KW,
|
||||
_ => return None,
|
||||
};
|
||||
Some(kw)
|
||||
|
@ -97,6 +97,7 @@ Grammar(
|
||||
"return",
|
||||
"try",
|
||||
"box",
|
||||
"await"
|
||||
],
|
||||
contextual_keywords: [
|
||||
"auto",
|
||||
@ -200,6 +201,7 @@ Grammar(
|
||||
"INDEX_EXPR",
|
||||
"METHOD_CALL_EXPR",
|
||||
"FIELD_EXPR",
|
||||
"AWAIT_EXPR",
|
||||
"TRY_EXPR",
|
||||
"CAST_EXPR",
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
fn foo() {
|
||||
x.await;
|
||||
x.0.await;
|
||||
x.0().await?.hello();
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
SOURCE_FILE@[0; 67)
|
||||
FN_DEF@[0; 66)
|
||||
FN_KW@[0; 2) "fn"
|
||||
WHITESPACE@[2; 3) " "
|
||||
NAME@[3; 6)
|
||||
IDENT@[3; 6) "foo"
|
||||
PARAM_LIST@[6; 8)
|
||||
L_PAREN@[6; 7) "("
|
||||
R_PAREN@[7; 8) ")"
|
||||
WHITESPACE@[8; 9) " "
|
||||
BLOCK@[9; 66)
|
||||
L_CURLY@[9; 10) "{"
|
||||
WHITESPACE@[10; 15) "\n "
|
||||
EXPR_STMT@[15; 23)
|
||||
AWAIT_EXPR@[15; 22)
|
||||
PATH_EXPR@[15; 16)
|
||||
PATH@[15; 16)
|
||||
PATH_SEGMENT@[15; 16)
|
||||
NAME_REF@[15; 16)
|
||||
IDENT@[15; 16) "x"
|
||||
DOT@[16; 17) "."
|
||||
AWAIT_KW@[17; 22) "await"
|
||||
SEMI@[22; 23) ";"
|
||||
WHITESPACE@[23; 28) "\n "
|
||||
EXPR_STMT@[28; 38)
|
||||
AWAIT_EXPR@[28; 37)
|
||||
FIELD_EXPR@[28; 31)
|
||||
PATH_EXPR@[28; 29)
|
||||
PATH@[28; 29)
|
||||
PATH_SEGMENT@[28; 29)
|
||||
NAME_REF@[28; 29)
|
||||
IDENT@[28; 29) "x"
|
||||
DOT@[29; 30) "."
|
||||
INT_NUMBER@[30; 31) "0"
|
||||
DOT@[31; 32) "."
|
||||
AWAIT_KW@[32; 37) "await"
|
||||
SEMI@[37; 38) ";"
|
||||
WHITESPACE@[38; 43) "\n "
|
||||
EXPR_STMT@[43; 64)
|
||||
METHOD_CALL_EXPR@[43; 63)
|
||||
TRY_EXPR@[43; 55)
|
||||
AWAIT_EXPR@[43; 54)
|
||||
CALL_EXPR@[43; 48)
|
||||
FIELD_EXPR@[43; 46)
|
||||
PATH_EXPR@[43; 44)
|
||||
PATH@[43; 44)
|
||||
PATH_SEGMENT@[43; 44)
|
||||
NAME_REF@[43; 44)
|
||||
IDENT@[43; 44) "x"
|
||||
DOT@[44; 45) "."
|
||||
INT_NUMBER@[45; 46) "0"
|
||||
ARG_LIST@[46; 48)
|
||||
L_PAREN@[46; 47) "("
|
||||
R_PAREN@[47; 48) ")"
|
||||
DOT@[48; 49) "."
|
||||
AWAIT_KW@[49; 54) "await"
|
||||
QUESTION@[54; 55) "?"
|
||||
DOT@[55; 56) "."
|
||||
NAME_REF@[56; 61)
|
||||
IDENT@[56; 61) "hello"
|
||||
ARG_LIST@[61; 63)
|
||||
L_PAREN@[61; 62) "("
|
||||
R_PAREN@[62; 63) ")"
|
||||
SEMI@[63; 64) ";"
|
||||
WHITESPACE@[64; 65) "\n"
|
||||
R_CURLY@[65; 66) "}"
|
||||
WHITESPACE@[66; 67) "\n"
|
Loading…
Reference in New Issue
Block a user