Skip to content

Commit

Permalink
feat: support labeled blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Nov 17, 2023
1 parent 25dfe48 commit 99c6922
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
17 changes: 9 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ module.exports = grammar({
$.extern_modifier,
)),

where_clause: $ => seq(
where_clause: $ => prec.right(seq(
'where',
sepBy1(',', $.where_predicate),
optional(','),
),
)),

where_predicate: $ => seq(
field('left', choice(
Expand Down Expand Up @@ -1206,20 +1206,20 @@ module.exports = grammar({
),

while_expression: $ => seq(
optional(seq($.loop_label, ':')),
optional(seq($.label, ':')),
'while',
field('condition', $._condition),
field('body', $.block),
),

loop_expression: $ => seq(
optional(seq($.loop_label, ':')),
optional(seq($.label, ':')),
'loop',
field('body', $.block),
),

for_expression: $ => seq(
optional(seq($.loop_label, ':')),
optional(seq($.label, ':')),
'for',
field('pattern', $._pattern),
'in',
Expand Down Expand Up @@ -1254,11 +1254,11 @@ module.exports = grammar({
'|',
),

loop_label: $ => seq('\'', $.identifier),
label: $ => seq('\'', $.identifier),

break_expression: $ => prec.left(seq('break', optional($.loop_label), optional($._expression))),
break_expression: $ => prec.left(seq('break', optional($.label), optional($._expression))),

continue_expression: $ => prec.left(seq('continue', optional($.loop_label))),
continue_expression: $ => prec.left(seq('continue', optional($.label))),

index_expression: $ => prec(PREC.call, seq($._expression, '[', $._expression, ']')),

Expand Down Expand Up @@ -1289,6 +1289,7 @@ module.exports = grammar({
),

block: $ => seq(
optional(seq($.label, ':')),
'{',
repeat($._statement),
optional($._expression),
Expand Down
14 changes: 7 additions & 7 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -837,17 +837,17 @@ Loop expressions
(source_file
(expression_statement
(loop_expression
(loop_label
(label
(identifier))
(block
(expression_statement
(loop_expression
(loop_label
(label
(identifier))
(block
(expression_statement
(break_expression
(loop_label
(label
(identifier))))
(expression_statement
(break_expression
Expand Down Expand Up @@ -899,7 +899,7 @@ for i in 0..256 {
(identifier)))))))
(expression_statement
(for_expression
(loop_label
(label
(identifier))
(identifier)
(range_expression
Expand All @@ -908,7 +908,7 @@ for i in 0..256 {
(block
(expression_statement
(for_expression
(loop_label
(label
(identifier))
(identifier)
(range_expression
Expand All @@ -925,7 +925,7 @@ for i in 0..256 {
(block
(expression_statement
(continue_expression
(loop_label
(label
(identifier)))))))
(expression_statement
(if_expression
Expand All @@ -937,7 +937,7 @@ for i in 0..256 {
(block
(expression_statement
(continue_expression
(loop_label
(label
(identifier))))))))))))))

================================================================================
Expand Down

0 comments on commit 99c6922

Please sign in to comment.