From ad72699553c39f159f25a6dc7ecd5df953817407 Mon Sep 17 00:00:00 2001 From: Caio Date: Sat, 9 Mar 2019 20:40:22 -0300 Subject: Add async keyword --- crates/ra_parser/src/grammar/expressions/atom.rs | 5 +++++ crates/ra_parser/src/grammar/items.rs | 10 +++++++++- crates/ra_parser/src/syntax_kind/generated.rs | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser/src') diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 9f282c74d..53bb26c5f 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -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), UNSAFE_KW if la == L_CURLY => { let m = p.start(); diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index ab9d2de90..91f9bfe8a 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -86,9 +86,14 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem { } let mut has_mods = false; + // modifiers - has_mods |= p.eat(CONST_KW); + 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 // fn foo(){} unsafe { } fn bar(){} 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 let kind = match p.current() { + // test async_fn + // async fn foo() {} + // test extern_fn // extern fn foo() {} diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 0eed44ecf..03247ae38 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -66,6 +66,7 @@ pub enum SyntaxKind { SHR, SHLEQ, SHREQ, + ASYNC_KW, USE_KW, FN_KW, STRUCT_KW, @@ -233,6 +234,7 @@ use self::SyntaxKind::*; impl SyntaxKind { pub fn is_keyword(self) -> bool { match self { + | ASYNC_KW | USE_KW | FN_KW | STRUCT_KW @@ -403,6 +405,7 @@ impl SyntaxKind { SHR => &SyntaxInfo { name: "SHR" }, SHLEQ => &SyntaxInfo { name: "SHLEQ" }, SHREQ => &SyntaxInfo { name: "SHREQ" }, + ASYNC_KW => &SyntaxInfo { name: "ASYNC_KW" }, USE_KW => &SyntaxInfo { name: "USE_KW" }, FN_KW => &SyntaxInfo { name: "FN_KW" }, STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" }, @@ -570,6 +573,7 @@ impl SyntaxKind { } pub fn from_keyword(ident: &str) -> Option { let kw = match ident { + "async" => ASYNC_KW, "use" => USE_KW, "fn" => FN_KW, "struct" => STRUCT_KW, -- cgit v1.2.3