mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Add async keyword
This commit is contained in:
parent
a9d09b7ec0
commit
ad72699553
8 changed files with 40 additions and 3 deletions
|
@ -93,6 +93,11 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASYNC_KW if la == L_CURLY => {
|
||||||
|
let m = p.start();
|
||||||
|
p.bump();
|
||||||
|
block_expr(p, Some(m))
|
||||||
|
}
|
||||||
MATCH_KW => match_expr(p),
|
MATCH_KW => match_expr(p),
|
||||||
UNSAFE_KW if la == L_CURLY => {
|
UNSAFE_KW if la == L_CURLY => {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
|
|
|
@ -86,9 +86,14 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut has_mods = false;
|
let mut has_mods = false;
|
||||||
// modifiers
|
|
||||||
has_mods |= p.eat(CONST_KW);
|
|
||||||
|
|
||||||
|
// modifiers
|
||||||
|
|
||||||
|
has_mods |= p.eat(CONST_KW);
|
||||||
|
if p.at(ASYNC_KW) && p.nth(1) != L_CURLY {
|
||||||
|
p.eat(ASYNC_KW);
|
||||||
|
has_mods = true;
|
||||||
|
}
|
||||||
// test_err unsafe_block_in_mod
|
// test_err unsafe_block_in_mod
|
||||||
// fn foo(){} unsafe { } fn bar(){}
|
// fn foo(){} unsafe { } fn bar(){}
|
||||||
if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY {
|
if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY {
|
||||||
|
@ -110,6 +115,9 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
|
||||||
|
|
||||||
// items
|
// items
|
||||||
let kind = match p.current() {
|
let kind = match p.current() {
|
||||||
|
// test async_fn
|
||||||
|
// async fn foo() {}
|
||||||
|
|
||||||
// test extern_fn
|
// test extern_fn
|
||||||
// extern fn foo() {}
|
// extern fn foo() {}
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ pub enum SyntaxKind {
|
||||||
SHR,
|
SHR,
|
||||||
SHLEQ,
|
SHLEQ,
|
||||||
SHREQ,
|
SHREQ,
|
||||||
|
ASYNC_KW,
|
||||||
USE_KW,
|
USE_KW,
|
||||||
FN_KW,
|
FN_KW,
|
||||||
STRUCT_KW,
|
STRUCT_KW,
|
||||||
|
@ -233,6 +234,7 @@ use self::SyntaxKind::*;
|
||||||
impl SyntaxKind {
|
impl SyntaxKind {
|
||||||
pub fn is_keyword(self) -> bool {
|
pub fn is_keyword(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
|
| ASYNC_KW
|
||||||
| USE_KW
|
| USE_KW
|
||||||
| FN_KW
|
| FN_KW
|
||||||
| STRUCT_KW
|
| STRUCT_KW
|
||||||
|
@ -403,6 +405,7 @@ impl SyntaxKind {
|
||||||
SHR => &SyntaxInfo { name: "SHR" },
|
SHR => &SyntaxInfo { name: "SHR" },
|
||||||
SHLEQ => &SyntaxInfo { name: "SHLEQ" },
|
SHLEQ => &SyntaxInfo { name: "SHLEQ" },
|
||||||
SHREQ => &SyntaxInfo { name: "SHREQ" },
|
SHREQ => &SyntaxInfo { name: "SHREQ" },
|
||||||
|
ASYNC_KW => &SyntaxInfo { name: "ASYNC_KW" },
|
||||||
USE_KW => &SyntaxInfo { name: "USE_KW" },
|
USE_KW => &SyntaxInfo { name: "USE_KW" },
|
||||||
FN_KW => &SyntaxInfo { name: "FN_KW" },
|
FN_KW => &SyntaxInfo { name: "FN_KW" },
|
||||||
STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" },
|
STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" },
|
||||||
|
@ -570,6 +573,7 @@ impl SyntaxKind {
|
||||||
}
|
}
|
||||||
pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
|
pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
|
||||||
let kw = match ident {
|
let kw = match ident {
|
||||||
|
"async" => ASYNC_KW,
|
||||||
"use" => USE_KW,
|
"use" => USE_KW,
|
||||||
"fn" => FN_KW,
|
"fn" => FN_KW,
|
||||||
"struct" => STRUCT_KW,
|
"struct" => STRUCT_KW,
|
||||||
|
|
|
@ -59,6 +59,7 @@ Grammar(
|
||||||
[">>=", "SHREQ"],
|
[">>=", "SHREQ"],
|
||||||
],
|
],
|
||||||
keywords: [
|
keywords: [
|
||||||
|
"async",
|
||||||
"use",
|
"use",
|
||||||
"fn",
|
"fn",
|
||||||
"struct",
|
"struct",
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
fn use struct trait enum impl true false as extern crate
|
async fn use struct trait enum impl true false as extern crate
|
||||||
mod pub self super in where for loop while if match const
|
mod pub self super in where for loop while if match const
|
||||||
static mut type ref let else move return
|
static mut type ref let else move return
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
ASYNC_KW 5 "async"
|
||||||
|
WHITESPACE 1 " "
|
||||||
FN_KW 2 "fn"
|
FN_KW 2 "fn"
|
||||||
WHITESPACE 1 " "
|
WHITESPACE 1 " "
|
||||||
USE_KW 3 "use"
|
USE_KW 3 "use"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
async fn foo() {}
|
|
@ -0,0 +1,16 @@
|
||||||
|
SOURCE_FILE@[0; 18)
|
||||||
|
FN_DEF@[0; 17)
|
||||||
|
ASYNC_KW@[0; 5)
|
||||||
|
WHITESPACE@[5; 6)
|
||||||
|
FN_KW@[6; 8)
|
||||||
|
WHITESPACE@[8; 9)
|
||||||
|
NAME@[9; 12)
|
||||||
|
IDENT@[9; 12) "foo"
|
||||||
|
PARAM_LIST@[12; 14)
|
||||||
|
L_PAREN@[12; 13)
|
||||||
|
R_PAREN@[13; 14)
|
||||||
|
WHITESPACE@[14; 15)
|
||||||
|
BLOCK@[15; 17)
|
||||||
|
L_CURLY@[15; 16)
|
||||||
|
R_CURLY@[16; 17)
|
||||||
|
WHITESPACE@[17; 18)
|
Loading…
Add table
Add a link
Reference in a new issue