aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs5
-rw-r--r--crates/ra_parser/src/grammar/items.rs10
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs4
-rw-r--r--crates/ra_syntax/src/grammar.ron1
-rw-r--r--crates/ra_syntax/tests/data/lexer/0011_keywords.rs2
-rw-r--r--crates/ra_syntax/tests/data/lexer/0011_keywords.txt2
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.rs1
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.txt16
8 files changed, 39 insertions, 2 deletions
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
93 } 93 }
94 } 94 }
95 95
96 ASYNC_KW if la == L_CURLY => {
97 let m = p.start();
98 p.bump();
99 block_expr(p, Some(m))
100 }
96 MATCH_KW => match_expr(p), 101 MATCH_KW => match_expr(p),
97 UNSAFE_KW if la == L_CURLY => { 102 UNSAFE_KW if la == L_CURLY => {
98 let m = p.start(); 103 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 {
86 } 86 }
87 87
88 let mut has_mods = false; 88 let mut has_mods = false;
89
89 // modifiers 90 // modifiers
90 has_mods |= p.eat(CONST_KW);
91 91
92 has_mods |= p.eat(CONST_KW);
93 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY {
94 p.eat(ASYNC_KW);
95 has_mods = true;
96 }
92 // test_err unsafe_block_in_mod 97 // test_err unsafe_block_in_mod
93 // fn foo(){} unsafe { } fn bar(){} 98 // fn foo(){} unsafe { } fn bar(){}
94 if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY { 99 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 {
110 115
111 // items 116 // items
112 let kind = match p.current() { 117 let kind = match p.current() {
118 // test async_fn
119 // async fn foo() {}
120
113 // test extern_fn 121 // test extern_fn
114 // extern fn foo() {} 122 // extern fn foo() {}
115 123
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 {
66 SHR, 66 SHR,
67 SHLEQ, 67 SHLEQ,
68 SHREQ, 68 SHREQ,
69 ASYNC_KW,
69 USE_KW, 70 USE_KW,
70 FN_KW, 71 FN_KW,
71 STRUCT_KW, 72 STRUCT_KW,
@@ -233,6 +234,7 @@ use self::SyntaxKind::*;
233impl SyntaxKind { 234impl SyntaxKind {
234 pub fn is_keyword(self) -> bool { 235 pub fn is_keyword(self) -> bool {
235 match self { 236 match self {
237 | ASYNC_KW
236 | USE_KW 238 | USE_KW
237 | FN_KW 239 | FN_KW
238 | STRUCT_KW 240 | STRUCT_KW
@@ -403,6 +405,7 @@ impl SyntaxKind {
403 SHR => &SyntaxInfo { name: "SHR" }, 405 SHR => &SyntaxInfo { name: "SHR" },
404 SHLEQ => &SyntaxInfo { name: "SHLEQ" }, 406 SHLEQ => &SyntaxInfo { name: "SHLEQ" },
405 SHREQ => &SyntaxInfo { name: "SHREQ" }, 407 SHREQ => &SyntaxInfo { name: "SHREQ" },
408 ASYNC_KW => &SyntaxInfo { name: "ASYNC_KW" },
406 USE_KW => &SyntaxInfo { name: "USE_KW" }, 409 USE_KW => &SyntaxInfo { name: "USE_KW" },
407 FN_KW => &SyntaxInfo { name: "FN_KW" }, 410 FN_KW => &SyntaxInfo { name: "FN_KW" },
408 STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" }, 411 STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" },
@@ -570,6 +573,7 @@ impl SyntaxKind {
570 } 573 }
571 pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { 574 pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
572 let kw = match ident { 575 let kw = match ident {
576 "async" => ASYNC_KW,
573 "use" => USE_KW, 577 "use" => USE_KW,
574 "fn" => FN_KW, 578 "fn" => FN_KW,
575 "struct" => STRUCT_KW, 579 "struct" => STRUCT_KW,
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index b7a2d1c01..66f1339c1 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -59,6 +59,7 @@ Grammar(
59 [">>=", "SHREQ"], 59 [">>=", "SHREQ"],
60 ], 60 ],
61 keywords: [ 61 keywords: [
62 "async",
62 "use", 63 "use",
63 "fn", 64 "fn",
64 "struct", 65 "struct",
diff --git a/crates/ra_syntax/tests/data/lexer/0011_keywords.rs b/crates/ra_syntax/tests/data/lexer/0011_keywords.rs
index e6bf64d4d..1e91bff4e 100644
--- a/crates/ra_syntax/tests/data/lexer/0011_keywords.rs
+++ b/crates/ra_syntax/tests/data/lexer/0011_keywords.rs
@@ -1,3 +1,3 @@
1fn use struct trait enum impl true false as extern crate 1async fn use struct trait enum impl true false as extern crate
2mod pub self super in where for loop while if match const 2mod pub self super in where for loop while if match const
3static mut type ref let else move return 3static mut type ref let else move return
diff --git a/crates/ra_syntax/tests/data/lexer/0011_keywords.txt b/crates/ra_syntax/tests/data/lexer/0011_keywords.txt
index d6a1abe8a..22c00eefb 100644
--- a/crates/ra_syntax/tests/data/lexer/0011_keywords.txt
+++ b/crates/ra_syntax/tests/data/lexer/0011_keywords.txt
@@ -1,3 +1,5 @@
1ASYNC_KW 5 "async"
2WHITESPACE 1 " "
1FN_KW 2 "fn" 3FN_KW 2 "fn"
2WHITESPACE 1 " " 4WHITESPACE 1 " "
3USE_KW 3 "use" 5USE_KW 3 "use"
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.rs
new file mode 100644
index 000000000..f4adcb62b
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.rs
@@ -0,0 +1 @@
async fn foo() {}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.txt
new file mode 100644
index 000000000..d1a706ecc
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0124_async_fn.txt
@@ -0,0 +1,16 @@
1SOURCE_FILE@[0; 18)
2 FN_DEF@[0; 17)
3 ASYNC_KW@[0; 5)
4 WHITESPACE@[5; 6)
5 FN_KW@[6; 8)
6 WHITESPACE@[8; 9)
7 NAME@[9; 12)
8 IDENT@[9; 12) "foo"
9 PARAM_LIST@[12; 14)
10 L_PAREN@[12; 13)
11 R_PAREN@[13; 14)
12 WHITESPACE@[14; 15)
13 BLOCK@[15; 17)
14 L_CURLY@[15; 16)
15 R_CURLY@[16; 17)
16 WHITESPACE@[17; 18)