Skip to content

Commit

Permalink
Merge branch 'master' into wip/sip-64-colon
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Dec 17, 2024
2 parents 9e1671f + fb9aa82 commit 4ef969d
Show file tree
Hide file tree
Showing 9 changed files with 404,611 additions and 404,542 deletions.
56 changes: 51 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ module.exports = grammar({
[$.class_parameters],
// 'for' operator_identifier ':' _annotated_type • ':' …
[$._type, $.compound_type],
// 'given' '(' operator_identifier ':' _type • ',' …
[$.name_and_type, $.parameter],
[$._simple_expression, $.binding, $.tuple_pattern],
[$._simple_expression, $.tuple_pattern],
[$._simple_expression, $._type_identifier],
// 'if' parenthesized_expression • '{' …
[$._if_condition, $._simple_expression],
[$.block, $._braced_template_body1],
Expand Down Expand Up @@ -575,10 +580,14 @@ module.exports = grammar({
prec.right(
seq(
field("name", $._identifier),
field("type_parameters", optional($.type_parameters)),
field(
"parameters",
repeat(seq(optional($._automatic_semicolon), $.parameters)),
repeat(
seq(
optional($._automatic_semicolon),
choice($.parameters, $.type_parameters),
),
),
),
optional($._automatic_semicolon),
),
Expand Down Expand Up @@ -818,6 +827,19 @@ module.exports = grammar({
),
),

/*
* NameAndType ::= id ':' Type
*/
name_and_type: $ =>
prec.left(
PREC.control,
seq(
field("name", $._identifier),
":",
field("type", $._param_type),
),
),

_block: $ =>
prec.left(
seq(
Expand Down Expand Up @@ -872,6 +894,7 @@ module.exports = grammar({
$.generic_type,
$.projected_type,
$.tuple_type,
$.named_tuple_type,
$.singleton_type,
$.stable_type_identifier,
$._type_identifier,
Expand Down Expand Up @@ -933,6 +956,12 @@ module.exports = grammar({

tuple_type: $ => seq("(", trailingCommaSep1($._type), ")"),

Check notice on line 957 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, complexity of the most complex definition tuple_type: 1221, lower than the allowed ceiling 1400

named_tuple_type: $ => seq(
"(",
trailingCommaSep1($.name_and_type),
")",
),

singleton_type: $ =>
prec.left(
PREC.stable_type_id,
Expand Down Expand Up @@ -1027,6 +1056,7 @@ module.exports = grammar({
$.interpolated_string_expression,
$.capture_pattern,
$.tuple_pattern,
$.named_tuple_pattern,
$.case_class_pattern,
$.infix_pattern,
$.alternative_pattern,
Expand All @@ -1042,7 +1072,10 @@ module.exports = grammar({
seq(
field("type", choice($._type_identifier, $.stable_type_identifier)),
"(",
field("pattern", trailingCommaSep($._pattern)),
choice(
field("pattern", trailingCommaSep($._pattern)),
field("pattern", trailingCommaSep($.named_pattern)),
),
")",
),

Expand Down Expand Up @@ -1070,15 +1103,28 @@ module.exports = grammar({

typed_pattern: $ =>
prec.right(
-1,
seq(field("pattern", $._pattern), ":", field("type", $._type)),
),

given_pattern: $ => seq("given", field("type", $._type)),

// TODO: Flatten this.
alternative_pattern: $ => prec.left(-1, seq($._pattern, "|", $._pattern)),
alternative_pattern: $ => prec.left(-2, seq($._pattern, "|", $._pattern)),

tuple_pattern: $ => seq(
"(",
trailingCommaSep1($._pattern),
")",
),

named_pattern: $ => prec.left(-1, seq($._identifier, "=", $._pattern)),

tuple_pattern: $ => seq("(", $._pattern, repeat(seq(",", $._pattern)), ")"),
named_tuple_pattern: $ => seq(
"(",
trailingCommaSep1($.named_pattern),
")",
),

// ---------------------------------------------------------------
// Expressions
Expand Down
Loading

0 comments on commit 4ef969d

Please sign in to comment.