Skip to content

Commit

Permalink
allow more patterns in constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Jun 19, 2024
1 parent 76e36a8 commit 34d4901
Show file tree
Hide file tree
Showing 5 changed files with 365,646 additions and 365,714 deletions.
39 changes: 15 additions & 24 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,22 @@ module.exports = grammar({
// Top-level rules (END)
//

primary_constr_args: ($) =>
seq(
optional($.attributes),
optional($.access_modifier),
"(",
optional($._pattern),
")",
optional(seq("as", $.identifier)),
),

//
// Pattern rules (BEGIN)

repeat_pattern: ($) =>
prec.right(seq($._pattern, repeat1(prec(1, seq(",", $._pattern))))),

_pattern: ($) =>
choice(
"null",
Expand All @@ -289,7 +303,7 @@ module.exports = grammar({
$.identifier_pattern,
),

optional_pattern: ($) => prec.right(seq("?", $._pattern)),
optional_pattern: ($) => prec.left(seq("?", $._pattern)),

type_check_pattern: ($) =>
prec.right(seq(":?", $.atomic_type, optional(seq("as", $.identifier)))),
Expand All @@ -298,9 +312,6 @@ module.exports = grammar({

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

repeat_pattern: ($) =>
prec.right(seq($._pattern, repeat1(prec.right(seq(",", $._pattern))))),

as_pattern: ($) => prec.left(0, seq($._pattern, "as", $.identifier)),
cons_pattern: ($) => prec.left(0, seq($._pattern, "::", $._pattern)),
disjunct_pattern: ($) => prec.left(0, seq($._pattern, "|", $._pattern)),
Expand Down Expand Up @@ -1317,26 +1328,6 @@ module.exports = grammar({
),
),

primary_constr_args: ($) =>
field(
"constructor",
seq(
optional($.attributes),
optional($.access_modifier),
"(",
optional(
seq(
$.simple_pattern,
repeat(prec.left(PREC.COMMA, seq(",", $.simple_pattern))),
),
),
")",
),
),

simple_pattern: ($) =>
choice($.identifier, seq($.simple_pattern, ":", $.type)),

_class_function_or_value_defn: ($) =>
seq(
optional($.attributes),
Expand Down
242 changes: 104 additions & 138 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 34d4901

Please sign in to comment.