Merge pull request #341 from eed3si9n/wip/anonymous_given

Fixes anonymous givens
pull/659/head
Chris Kipp 2023-09-01 08:07:37 +07:00 committed by GitHub
commit 57f19d39a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 20 deletions

@ -1219,9 +1219,6 @@ object A:
given foo(using ev: Foo)
: Foo = ev
given [T: Ordering]: Ordering[List[T]] with
def x = ()
given Context = ctx
given Context[T] = ctx
@ -1229,6 +1226,14 @@ object A:
given Foo[Int] =
case n => "123"
given (using a: Int): Int = a
given [A: Foo]: Foo[List[A]] with
def x = ()
given [A](using Foo[A]): Foo[List[A]] with
def x = ()
--------------------------------------------------------------------------------
(compilation_unit
@ -1309,8 +1314,31 @@ object A:
(type_identifier)
(identifier))
(given_definition
(identifier
(MISSING _alpha_identifier))
(type_identifier)
(identifier))
(given_definition
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(identifier))
(given_definition
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(indented_cases
(case_clause
(identifier)
(string))))
(given_definition
(parameters
(parameter
(identifier)
(type_identifier)))
(type_identifier)
(identifier))
(given_definition
(type_parameters
(identifier)
(context_bound
@ -1327,23 +1355,24 @@ object A:
(identifier)
(unit))))
(given_definition
(type_identifier)
(identifier))
(given_definition
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(identifier))
(given_definition
(type_parameters
(identifier))
(parameters
(generic_type
(type_identifier)
(type_arguments
(type_identifier))))
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(indented_cases
(case_clause
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))
(with_template_body
(function_definition
(identifier)
(string)))))))
(unit)))))))
================================================================================
Top-level Definitions (Scala 3 syntax)

@ -70,6 +70,7 @@ module.exports = grammar({
[$.if_expression],
[$.match_expression],
[$._function_constructor, $._type_identifier],
[$._given_constructor, $._type_identifier],
[$.instance_expression],
// In case of: 'extension' _indent '{' 'case' operator_identifier 'if' operator_identifier • '=>' …
// we treat `operator_identifier` as `simple_expression`
@ -583,7 +584,7 @@ module.exports = grammar({
repeat($.annotation),
optional($.modifiers),
"given",
optional(seq($._function_constructor, ":")),
optional($._given_constructor),
choice(
field("return_type", $._structural_instance),
seq(
@ -595,6 +596,20 @@ module.exports = grammar({
),
),
_given_constructor: $ =>
prec.right(
seq(
field("name", optional($._identifier)),
field("type_parameters", optional($.type_parameters)),
field(
"parameters",
repeat(seq(optional($._automatic_semicolon), $.parameters)),
),
optional($._automatic_semicolon),
":",
),
),
/**
* StructuralInstance ::= ConstrApp {'with' ConstrApp} ['with' WithTemplateBody]
*/

@ -4,7 +4,7 @@
SCALA_SCALA_LIBRARY_EXPECTED=100
SCALA_SCALA_COMPILER_EXPECTED=96
DOTTY_COMPILER_EXPECTED=84
DOTTY_COMPILER_EXPECTED=83
SYNTAX_COMPLEXITY_CEILING=1300
if [ ! -d "$SCALA_SCALA_DIR" ]; then