Skip to content

Commit

Permalink
feat: named pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Sep 10, 2024
1 parent 3d35062 commit 5be440e
Show file tree
Hide file tree
Showing 9 changed files with 845,358 additions and 859,282 deletions.
1 change: 1 addition & 0 deletions examples/playground/test.fsi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val:[<g^constr~™tort.1.[pSp◊rr<<T-ac}
19 changes: 16 additions & 3 deletions fsharp/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ module.exports = grammar({
$.type_check_pattern,
$.optional_pattern,
$.identifier_pattern,
$.named_field_pattern,
),

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

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

paren_pattern: ($) => seq("(", $._pattern, ")"),
paren_pattern: ($) => prec(1, seq("(", $._pattern, ")")),

as_pattern: ($) => prec.left(0, seq($._pattern, "as", $.identifier)),
cons_pattern: ($) => prec.left(0, seq($._pattern, "::", $._pattern)),
Expand Down Expand Up @@ -377,7 +378,7 @@ module.exports = grammar({
seq(
optional($._newline),
$._pattern,
repeat(seq(choice(";", $._newline), $._pattern)),
repeat(seq($._newline, $._pattern)),
),
$._indent,
$._dedent,
Expand All @@ -387,7 +388,19 @@ module.exports = grammar({
array_pattern: ($) => seq("[|", optional($._list_pattern_content), "|]"),
record_pattern: ($) =>
prec.left(
seq("{", $.field_pattern, repeat(seq(";", $.field_pattern)), "}"),
seq(
"{",
$.field_pattern,
repeat(seq($._newline, $.field_pattern)),
"}",
),
),

named_field: ($) => seq(optional(seq($.identifier, "=")), $._pattern),

named_field_pattern: ($) =>
prec.left(
seq("(", $.named_field, repeat(seq($._newline, $.named_field)), ")"),
),

identifier_pattern: ($) =>
Expand Down
Loading

0 comments on commit 5be440e

Please sign in to comment.