Skip to content

Commit 7cd2dca

Browse files
GrayJackmaxbrunsfeld
authored andcommitted
Parse async blocks (#44)
* Parse async blocks * Await blocks ca also have move
1 parent bdf057c commit 7cd2dca

File tree

5 files changed

+77564
-76667
lines changed

5 files changed

+77564
-76667
lines changed

corpus/async.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,24 @@ futures.await?.function().await?;
4848
(await_expression (identifier)))
4949
(field_identifier))
5050
(arguments)))))
51+
52+
============================================
53+
Async Block
54+
============================================
55+
56+
async {}
57+
async { let x = 10; }
58+
async move {}
59+
60+
---
61+
62+
(source_file
63+
(async_block
64+
(block))
65+
(async_block
66+
(block
67+
(let_declaration
68+
(identifier)
69+
(integer_literal))))
70+
(async_block
71+
(block)))

grammar.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ module.exports = grammar({
844844

845845
_expression_ending_with_block: $ => choice(
846846
$.unsafe_block,
847+
$.async_block,
847848
$.block,
848849
$.if_expression,
849850
$.if_let_expression,
@@ -1188,6 +1189,12 @@ module.exports = grammar({
11881189
$.block
11891190
),
11901191

1192+
async_block: $ => seq(
1193+
'async',
1194+
optional("move"),
1195+
$.block
1196+
),
1197+
11911198
block: $ => seq(
11921199
'{',
11931200
repeat($._statement),

src/grammar.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4662,6 +4662,10 @@
46624662
"type": "SYMBOL",
46634663
"name": "unsafe_block"
46644664
},
4665+
{
4666+
"type": "SYMBOL",
4667+
"name": "async_block"
4668+
},
46654669
{
46664670
"type": "SYMBOL",
46674671
"name": "block"
@@ -6881,6 +6885,31 @@
68816885
}
68826886
]
68836887
},
6888+
"async_block": {
6889+
"type": "SEQ",
6890+
"members": [
6891+
{
6892+
"type": "STRING",
6893+
"value": "async"
6894+
},
6895+
{
6896+
"type": "CHOICE",
6897+
"members": [
6898+
{
6899+
"type": "STRING",
6900+
"value": "move"
6901+
},
6902+
{
6903+
"type": "BLANK"
6904+
}
6905+
]
6906+
},
6907+
{
6908+
"type": "SYMBOL",
6909+
"name": "block"
6910+
}
6911+
]
6912+
},
68846913
"block": {
68856914
"type": "SEQ",
68866915
"members": [

src/node-types.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
"type": "assignment_expression",
106106
"named": true
107107
},
108+
{
109+
"type": "async_block",
110+
"named": true
111+
},
108112
{
109113
"type": "await_expression",
110114
"named": true
@@ -594,6 +598,21 @@
594598
}
595599
}
596600
},
601+
{
602+
"type": "async_block",
603+
"named": true,
604+
"fields": {},
605+
"children": {
606+
"multiple": false,
607+
"required": true,
608+
"types": [
609+
{
610+
"type": "block",
611+
"named": true
612+
}
613+
]
614+
}
615+
},
597616
{
598617
"type": "attribute_item",
599618
"named": true,
@@ -759,6 +778,10 @@
759778
"type": "_expression",
760779
"named": true
761780
},
781+
{
782+
"type": "async_block",
783+
"named": true
784+
},
762785
{
763786
"type": "block",
764787
"named": true
@@ -3201,6 +3224,10 @@
32013224
"type": "_expression",
32023225
"named": true
32033226
},
3227+
{
3228+
"type": "async_block",
3229+
"named": true
3230+
},
32043231
{
32053232
"type": "block",
32063233
"named": true

0 commit comments

Comments
 (0)