Skip to content

Commit 7265977

Browse files
authored
Exponentiation operator ** is right-associative (#279)
Close #269
1 parent 0eb4659 commit 7265977

4 files changed

Lines changed: 8292 additions & 8270 deletions

File tree

grammar.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default grammar({
117117
[$._module_structure, $.parenthesized_module_expression],
118118
[$._record_type_member, $._object_type_member],
119119
[$._non_function_inline_type, $.generic_type],
120-
[$._type_identifier, $.polymorphic_type]
120+
[$._type_identifier, $.polymorphic_type],
121121
],
122122

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

143142
statement: ($) =>
144143
choice(
@@ -328,7 +327,10 @@ export default grammar({
328327

329328
variant_type: ($) =>
330329
prec.left(
331-
seq(optional("|"), barSep1(choice($.variant_declaration, $.variant_type_spread))),
330+
seq(
331+
optional("|"),
332+
barSep1(choice($.variant_declaration, $.variant_type_spread)),
333+
),
332334
),
333335

334336
variant_declaration: ($) =>
@@ -421,11 +423,7 @@ export default grammar({
421423
),
422424

423425
let_declaration: ($) =>
424-
seq(
425-
choice("export", "let"),
426-
optional("rec"),
427-
sep1("and", $.let_binding),
428-
),
426+
seq(choice("export", "let"), optional("rec"), sep1("and", $.let_binding)),
429427

430428
let_binding: ($) =>
431429
seq(
@@ -564,7 +562,8 @@ export default grammar({
564562

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

567-
array: ($) => seq("[", commaSept(choice($.spread_element, $.expression)), "]"),
565+
array: ($) =>
566+
seq("[", commaSept(choice($.spread_element, $.expression)), "]"),
568567

569568
list: ($) =>
570569
seq($._list_constructor, "{", optional(commaSep1t($._list_element)), "}"),
@@ -611,10 +610,7 @@ export default grammar({
611610
field("pattern", choice($.variant_spread_pattern, $._pattern)),
612611
optional($.guard),
613612
"=>",
614-
field(
615-
"body",
616-
alias($._switch_body, $.sequence_expression),
617-
),
613+
field("body", alias($._switch_body, $.sequence_expression)),
618614
),
619615
),
620616

@@ -1042,7 +1038,7 @@ export default grammar({
10421038
["*", "binary_times"],
10431039
["*.", "binary_times"],
10441040
["%", "binary_times"],
1045-
["**", "binary_pow"],
1041+
["**", "binary_pow", "right"],
10461042
["/", "binary_times"],
10471043
["/.", "binary_times"],
10481044
["<<", "binary_shift"],
@@ -1056,8 +1052,8 @@ export default grammar({
10561052
["!==", "binary_relation"],
10571053
[">=", "binary_relation"],
10581054
[">", "binary_relation"],
1059-
].map(([operator, precedence]) =>
1060-
prec.left(
1055+
].map(([operator, precedence, associativity]) =>
1056+
(associativity === "right" ? prec.right : prec.left)(
10611057
precedence,
10621058
seq(
10631059
field("left", $.expression),
@@ -1136,8 +1132,7 @@ export default grammar({
11361132
),
11371133
),
11381134

1139-
_type_identifier: ($) =>
1140-
choice($.type_identifier, $.type_identifier_path),
1135+
_type_identifier: ($) => choice($.type_identifier, $.type_identifier_path),
11411136

11421137
type_identifier_path: ($) =>
11431138
seq($.module_primary_expression, ".", $.type_identifier),
@@ -1430,10 +1425,6 @@ function commaSep2t(rule) {
14301425
return seq(commaSep2(rule), optional(","));
14311426
}
14321427

1433-
function commaSep(rule) {
1434-
return optional(commaSep1(rule));
1435-
}
1436-
14371428
function commaSept(rule) {
14381429
return optional(commaSep1t(rule));
14391430
}

src/grammar.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)