Skip to content

Commit

Permalink
feat: support gen block syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
flippette committed Nov 2, 2024
1 parent 2ace7a9 commit 6e5b4a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 9 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ module.exports = grammar({
alias(choice(...primitiveTypes), $.primitive_type),
prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))),
'\'',
'as', 'async', 'await', 'break', 'const', 'continue', 'default', 'enum', 'fn', 'for', 'if', 'impl',
'let', 'loop', 'match', 'mod', 'pub', 'return', 'static', 'struct', 'trait', 'type',
'union', 'unsafe', 'use', 'where', 'while',
'as', 'async', 'await', 'break', 'const', 'continue', 'default', 'enum', 'fn', 'for', 'gen',
'if', 'impl', 'let', 'loop', 'match', 'mod', 'pub', 'return', 'static', 'struct', 'trait',
'type', 'union', 'unsafe', 'use', 'where', 'while',
),

// Section - Declarations
Expand Down Expand Up @@ -931,6 +931,7 @@ module.exports = grammar({
_expression_ending_with_block: $ => choice(
$.unsafe_block,
$.async_block,
$.gen_block,
$.try_block,
$.block,
$.if_expression,
Expand Down Expand Up @@ -1255,6 +1256,11 @@ module.exports = grammar({
field('body', $.block),
),

gen_block: $ => seq(
'gen',
field('body', $.block),
),

closure_expression: $ => prec(PREC.closure, seq(
optional('static'),
optional('move'),
Expand Down
17 changes: 17 additions & 0 deletions test/corpus/async.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ try {}
(expression_statement
(try_block
(block))))

================================================================================
Gen Block
================================================================================

gen {}
gen move {}

--------------------------------------------------------------------------------

(source_file
(expression_statement
(gen_block
(block)))
(expression_statement
(gen_block
(block))))

0 comments on commit 6e5b4a7

Please sign in to comment.