Skip to content

Commit 7516d0f

Browse files
flippetteamaanq
authored andcommitted
feat: support gen block syntax
1 parent b1800a9 commit 7516d0f

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

grammar.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ module.exports = grammar({
239239
alias(choice(...primitiveTypes), $.primitive_type),
240240
prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))),
241241
'\'',
242-
'as', 'async', 'await', 'break', 'const', 'continue', 'default', 'enum', 'fn', 'for', 'if', 'impl',
243-
'let', 'loop', 'match', 'mod', 'pub', 'return', 'static', 'struct', 'trait', 'type',
244-
'union', 'unsafe', 'use', 'where', 'while',
242+
'as', 'async', 'await', 'break', 'const', 'continue', 'default', 'enum', 'fn', 'for', 'gen',
243+
'if', 'impl', 'let', 'loop', 'match', 'mod', 'pub', 'return', 'static', 'struct', 'trait',
244+
'type', 'union', 'unsafe', 'use', 'where', 'while',
245245
),
246246

247247
// Section - Declarations
@@ -931,6 +931,7 @@ module.exports = grammar({
931931
_expression_ending_with_block: $ => choice(
932932
$.unsafe_block,
933933
$.async_block,
934+
$.gen_block,
934935
$.try_block,
935936
$.block,
936937
$.if_expression,
@@ -1311,6 +1312,12 @@ module.exports = grammar({
13111312
$.block,
13121313
),
13131314

1315+
gen_block: $ => seq(
1316+
'gen',
1317+
optional('move'),
1318+
$.block,
1319+
),
1320+
13141321
try_block: $ => seq(
13151322
'try',
13161323
$.block,

queries/highlights.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"extern" @keyword
111111
"fn" @keyword
112112
"for" @keyword
113+
"gen" @keyword
113114
"if" @keyword
114115
"impl" @keyword
115116
"in" @keyword

test/corpus/async.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,34 @@ try {}
9999
(expression_statement
100100
(try_block
101101
(block))))
102+
103+
================================================================================
104+
Gen Block
105+
================================================================================
106+
107+
gen {}
108+
gen { let x = 10; }
109+
gen { yield (); }
110+
gen move {}
111+
112+
--------------------------------------------------------------------------------
113+
114+
(source_file
115+
(expression_statement
116+
(gen_block
117+
(block)))
118+
(expression_statement
119+
(gen_block
120+
(block
121+
(let_declaration
122+
(identifier)
123+
(integer_literal)))))
124+
(expression_statement
125+
(gen_block
126+
(block
127+
(expression_statement
128+
(yield_expression
129+
(unit_expression))))))
130+
(expression_statement
131+
(gen_block
132+
(block))))

0 commit comments

Comments
 (0)