Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default grammar({
[$._module_structure, $.parenthesized_module_expression],
[$._record_type_member, $._object_type_member],
[$._non_function_inline_type, $.generic_type],
[$._type_identifier, $.polymorphic_type]
[$._type_identifier, $.polymorphic_type],
],

rules: {
Expand All @@ -137,8 +137,7 @@ export default grammar({
// Used as switch_match / try-catch bodies so that trailing NEWLINEs
// (including those emitted between consecutive block comments) are
// absorbed by the enclosing switch/try rule instead of being orphaned.
_switch_body: ($) =>
seq(repeat($._statement), $.statement),
_switch_body: ($) => seq(repeat($._statement), $.statement),

statement: ($) =>
choice(
Expand Down Expand Up @@ -328,7 +327,10 @@ export default grammar({

variant_type: ($) =>
prec.left(
seq(optional("|"), barSep1(choice($.variant_declaration, $.variant_type_spread))),
seq(
optional("|"),
barSep1(choice($.variant_declaration, $.variant_type_spread)),
),
),

variant_declaration: ($) =>
Expand Down Expand Up @@ -421,11 +423,7 @@ export default grammar({
),

let_declaration: ($) =>
seq(
choice("export", "let"),
optional("rec"),
sep1("and", $.let_binding),
),
seq(choice("export", "let"), optional("rec"), sep1("and", $.let_binding)),

let_binding: ($) =>
seq(
Expand Down Expand Up @@ -564,7 +562,8 @@ export default grammar({

tuple: ($) => seq("(", commaSep2t($.expression), ")"),

array: ($) => seq("[", commaSept(choice($.spread_element, $.expression)), "]"),
array: ($) =>
seq("[", commaSept(choice($.spread_element, $.expression)), "]"),

list: ($) =>
seq($._list_constructor, "{", optional(commaSep1t($._list_element)), "}"),
Expand Down Expand Up @@ -611,10 +610,7 @@ export default grammar({
field("pattern", choice($.variant_spread_pattern, $._pattern)),
optional($.guard),
"=>",
field(
"body",
alias($._switch_body, $.sequence_expression),
),
field("body", alias($._switch_body, $.sequence_expression)),
),
),

Expand Down Expand Up @@ -1042,7 +1038,7 @@ export default grammar({
["*", "binary_times"],
["*.", "binary_times"],
["%", "binary_times"],
["**", "binary_pow"],
["**", "binary_pow", "right"],
["/", "binary_times"],
["/.", "binary_times"],
["<<", "binary_shift"],
Expand All @@ -1056,8 +1052,8 @@ export default grammar({
["!==", "binary_relation"],
[">=", "binary_relation"],
[">", "binary_relation"],
].map(([operator, precedence]) =>
prec.left(
].map(([operator, precedence, associativity]) =>
(associativity === "right" ? prec.right : prec.left)(
precedence,
seq(
field("left", $.expression),
Expand Down Expand Up @@ -1136,8 +1132,7 @@ export default grammar({
),
),

_type_identifier: ($) =>
choice($.type_identifier, $.type_identifier_path),
_type_identifier: ($) => choice($.type_identifier, $.type_identifier_path),

type_identifier_path: ($) =>
seq($.module_primary_expression, ".", $.type_identifier),
Expand Down Expand Up @@ -1430,10 +1425,6 @@ function commaSep2t(rule) {
return seq(commaSep2(rule), optional(","));
}

function commaSep(rule) {
return optional(commaSep1(rule));
}

function commaSept(rule) {
return optional(commaSep1t(rule));
}
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.json

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

Loading
Loading