Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIP-64 support #442

Merged
merged 6 commits into from
Dec 17, 2024
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
71 changes: 56 additions & 15 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const PREC = {

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, scala_scala/src/library/: 100.00%, expected at least 100%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, scala_scala/src/compiler/: 96.65%, expected at least 96%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, dotty/compiler/: 83.76%, expected at least 83%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, lila/modules/: 84.28%, expected at least 84%
comment: 1,
using_directive: 2,
control: 1,
stable_type_id: 2,
type: 2,
while: 2,
assign: 3,
case: 3,
Expand Down Expand Up @@ -98,8 +99,12 @@
[$._simple_expression, $._type_identifier],
// 'if' parenthesized_expression • '{' …
[$._if_condition, $._simple_expression],
// _postfix_expression_choice ':' '(' wildcard • ':' …
[$.binding, $._simple_type],
[$.block, $._braced_template_body1],
[$._simple_expression, $.self_type, $._type_identifier],
[$._simple_expression, $._type_identifier],
[$.lambda_expression, $.self_type, $._type_identifier],
[$.lambda_expression, $._type_identifier],
[$.binding, $._simple_expression, $._type_identifier],
],

word: $ => $._alpha_identifier,
Expand Down Expand Up @@ -369,7 +374,7 @@
field("bound", optional($.lower_bound)),
field("bound", optional($.upper_bound)),
field("bound", optional(repeat($.view_bound))),
field("bound", optional(repeat($.context_bound))),
field("bound", optional($._context_bounds)),
),

upper_bound: $ => seq("<:", field("type", $._type)),
Expand All @@ -378,7 +383,26 @@

view_bound: $ => seq("<%", field("type", $._type)),

context_bound: $ => seq(":", field("type", $._type)),
_context_bounds: $ => choice(
repeat1(seq(
":",
$.context_bound
)),
seq(
":",
"{",
trailingCommaSep1($.context_bound),
"}",
)
),

context_bound: $ => seq(
field("type", $._type),
optional(seq(
"as",
field("name", $._identifier),
)),
),

/*
* TemplateBody ::= :<<< [SelfType] TemplateStat {semi TemplateStat} >>>
Expand Down Expand Up @@ -525,6 +549,7 @@
field("type_parameters", optional($.type_parameters)),
field("bound", optional($.lower_bound)),
field("bound", optional($.upper_bound)),
field("bound", optional($._context_bounds)),
),
),

Expand Down Expand Up @@ -602,6 +627,7 @@
optional($.modifiers),
"given",
optional($._given_constructor),
repeat($._given_sig),
choice(
field("return_type", $._structural_instance),
seq(
Expand All @@ -612,6 +638,14 @@
),
),

_given_sig: $ =>
seq(
$._given_conditional,
"=>"
),

_given_conditional: $ => alias($.parameters, $.given_conditional),

_given_constructor: $ =>
prec.right(
seq(
Expand All @@ -634,7 +668,10 @@
PREC.compound,
seq(
$._constructor_application,
"with",
choice(
":",
"with"
),
field("body", $.with_template_body),
),
),
Expand Down Expand Up @@ -851,15 +888,18 @@
annotated_type: $ => prec.right(seq($._simple_type, repeat1($.annotation))),

_simple_type: $ =>
choice(
$.generic_type,
$.projected_type,
$.tuple_type,
$.named_tuple_type,
$.singleton_type,
$.stable_type_identifier,
$._type_identifier,
$.wildcard,
prec.left(
PREC.type,
choice(
$.generic_type,
$.projected_type,
$.tuple_type,
$.named_tuple_type,
$.singleton_type,
$.stable_type_identifier,
$._type_identifier,
$.wildcard,
)
),

compound_type: $ =>
Expand Down Expand Up @@ -914,7 +954,7 @@
),
),

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(
"(",
Expand Down Expand Up @@ -1562,7 +1602,8 @@
$.string,
),

literal_type: $ => $._non_null_literal,
literal_type: $ =>
prec.left(PREC.type, $._non_null_literal),

literal: $ => choice($._non_null_literal, $.null_literal),

Expand Down
50 changes: 49 additions & 1 deletion test/corpus/definitions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,25 @@ class A {
(type_parameters
(identifier))))))

================================================================================
Type definitions (Scala 3 syntax)
================================================================================

class A:
type Element: Order

--------------------------------------------------------------------------------

(compilation_unit
(class_definition
(identifier)
(template_body
(type_definition
(type_identifier)
(context_bound
(type_identifier))))))


================================================================================
Function declarations
================================================================================
Expand Down Expand Up @@ -1290,6 +1309,9 @@ object A:
given intFoo: CanFoo[Int] with
def foo(x: Int): Int = 0

given intFoo: CanFoo[Int]:
def foo(x: Int): Int = 0

given CanFoo[Int] with
def foo(x: Int): Int = 0

Expand Down Expand Up @@ -1317,6 +1339,8 @@ object A:
trait B:
given c: Context[T]

given (config: Config) => Factory = ConcreteFactory()

--------------------------------------------------------------------------------

(compilation_unit
Expand All @@ -1342,6 +1366,21 @@ object A:
(type_identifier)))
(type_identifier)
(integer_literal))))
(given_definition
(identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(with_template_body
(function_definition
(identifier)
(parameters
(parameter
(identifier)
(type_identifier)))
(type_identifier)
(integer_literal))))
(given_definition
(generic_type
(type_identifier)
Expand Down Expand Up @@ -1464,7 +1503,16 @@ object A:
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))))))
(type_identifier))))))
(given_definition
(given_conditional
(parameter
(identifier)
(type_identifier)))
(type_identifier)
(call_expression
(identifier)
(arguments))))))

================================================================================
Top-level Definitions (Scala 3 syntax)
Expand Down
45 changes: 45 additions & 0 deletions test/corpus/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,51 @@ class A[B : C : D]
(context_bound
(type_identifier)))))

================================================================================
Context bound (Scala 3 syntax)
================================================================================

def reduce[A : Monoid as m](xs: List[A]): A = ()

def showMax[X : {Ordering, Show}](x: X, y: X): String = ()

--------------------------------------------------------------------------------

(compilation_unit
(function_definition
(identifier)
(type_parameters
(identifier)
(context_bound
(type_identifier)
(identifier)))
(parameters
(parameter
(identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))
(type_identifier)
(unit))
(function_definition
(identifier)
(type_parameters
(identifier)
(context_bound
(type_identifier))
(context_bound
(type_identifier)))
(parameters
(parameter
(identifier)
(type_identifier))
(parameter
(identifier)
(type_identifier)))
(type_identifier)
(unit)))

================================================================================
Projections
================================================================================
Expand Down
Loading