Skip to content

Commit 5be440e

Browse files
committed
feat: named pattern
1 parent 3d35062 commit 5be440e

File tree

9 files changed

+845358
-859282
lines changed

9 files changed

+845358
-859282
lines changed

examples/playground/test.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val:[<g^constr~™tort.1.[pSp◊rr<<T-ac}

fsharp/grammar.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ module.exports = grammar({
322322
$.type_check_pattern,
323323
$.optional_pattern,
324324
$.identifier_pattern,
325+
$.named_field_pattern,
325326
),
326327

327328
optional_pattern: ($) => prec.left(seq("?", $._pattern)),
@@ -331,7 +332,7 @@ module.exports = grammar({
331332

332333
attribute_pattern: ($) => prec.left(seq($.attributes, $._pattern)),
333334

334-
paren_pattern: ($) => seq("(", $._pattern, ")"),
335+
paren_pattern: ($) => prec(1, seq("(", $._pattern, ")")),
335336

336337
as_pattern: ($) => prec.left(0, seq($._pattern, "as", $.identifier)),
337338
cons_pattern: ($) => prec.left(0, seq($._pattern, "::", $._pattern)),
@@ -377,7 +378,7 @@ module.exports = grammar({
377378
seq(
378379
optional($._newline),
379380
$._pattern,
380-
repeat(seq(choice(";", $._newline), $._pattern)),
381+
repeat(seq($._newline, $._pattern)),
381382
),
382383
$._indent,
383384
$._dedent,
@@ -387,7 +388,19 @@ module.exports = grammar({
387388
array_pattern: ($) => seq("[|", optional($._list_pattern_content), "|]"),
388389
record_pattern: ($) =>
389390
prec.left(
390-
seq("{", $.field_pattern, repeat(seq(";", $.field_pattern)), "}"),
391+
seq(
392+
"{",
393+
$.field_pattern,
394+
repeat(seq($._newline, $.field_pattern)),
395+
"}",
396+
),
397+
),
398+
399+
named_field: ($) => seq(optional(seq($.identifier, "=")), $._pattern),
400+
401+
named_field_pattern: ($) =>
402+
prec.left(
403+
seq("(", $.named_field, repeat(seq($._newline, $.named_field)), ")"),
391404
),
392405

393406
identifier_pattern: ($) =>

0 commit comments

Comments
 (0)