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 a411a29
Showing 1 changed file with 9 additions and 8 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

0 comments on commit a411a29

Please sign in to comment.