Skip to content

Commit 3573bf7

Browse files
authored
Merge pull request #297 from susliko/structural-types
Structural types in declarations
2 parents d42d40c + bc9fb98 commit 3573bf7

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

corpus/types.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ type G = H[A1] {
201201
type I = F1[A1:
202202
def foo: A2]
203203

204+
def a: F { val x: Int } = ???
205+
204206
--------------------------------------------------------------------------------
205207

206208
(compilation_unit
@@ -249,7 +251,16 @@ type I = F1[A1:
249251
(refinement
250252
(function_declaration
251253
(identifier)
252-
(type_identifier))))))))
254+
(type_identifier)))))))
255+
(function_definition
256+
(identifier)
257+
(compound_type
258+
(type_identifier)
259+
(refinement
260+
(val_declaration
261+
(identifier)
262+
(type_identifier))))
263+
(operator_identifier)))
253264

254265
================================================================================
255266
Infix types

grammar.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,11 @@ module.exports = grammar({
6565
conflicts: $ => [
6666
[$.tuple_type, $.parameter_types],
6767
[$.binding, $._simple_expression],
68-
[$.binding, $.ascription_expression],
6968
[$.binding, $._type_identifier],
70-
[$.if_expression, $.expression],
7169
[$.while_expression, $._simple_expression],
72-
[$.for_expression, $.infix_expression],
73-
[$._indentable_expression, $.do_while_expression],
7470
[$.if_expression],
7571
[$.match_expression],
7672
[$._function_constructor, $._type_identifier],
77-
[$._type_identifier, $.identifier],
7873
[$.instance_expression],
7974
// In case of: 'extension' _indent '{' 'case' operator_identifier 'if' operator_identifier • '=>' …
8075
// we treat `operator_identifier` as `simple_expression`
@@ -91,7 +86,10 @@ module.exports = grammar({
9186
[$._full_enum_def],
9287
// _start_val identifier ',' identifier • ':' …
9388
[$.identifiers, $.val_declaration],
89+
// 'enum' operator_identifier _automatic_semicolon '(' ')' • ':' …
9490
[$.class_parameters],
91+
// 'for' operator_identifier ':' _annotated_type • ':' …
92+
[$._type, $.compound_type]
9593
],
9694

9795
word: $ => $._alpha_identifier,
@@ -375,19 +373,19 @@ module.exports = grammar({
375373
*/
376374
template_body: $ =>
377375
choice(
378-
prec.left(PREC.control, $._indented_template_body),
379-
prec.left(PREC.control, $._braced_template_body),
376+
$._indented_template_body,
377+
$._braced_template_body,
380378
),
381379

382380
_indented_template_body: $ =>
383-
seq(":", $._indent, optional($.self_type), $._block, $._outdent),
381+
prec.left(PREC.control, seq(":", $._indent, optional($.self_type), $._block, $._outdent)),
384382

385383
_braced_template_body: $ =>
386-
seq(
384+
prec.left(PREC.control, seq(
387385
"{",
388386
optional(choice($._braced_template_body1, $._braced_template_body2)),
389387
"}",
390-
),
388+
)),
391389

392390
_braced_template_body1: $ => seq(optional($.self_type), $._block),
393391
_braced_template_body2: $ =>
@@ -812,7 +810,7 @@ module.exports = grammar({
812810
repeat1(seq("with", field("extra", $._annotated_type))),
813811
),
814812
),
815-
prec.left(-1, seq(field("base", $._annotated_type), $._refinement)),
813+
prec.left(seq(field("base", $._annotated_type), $._refinement)),
816814
prec.left(
817815
-1,
818816
seq(

script/smoke_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# This is an integration test to generally check the quality of parsing.
44

5-
SCALA_SCALA_LIBRARY_EXPECTED=98
6-
SCALA_SCALA_COMPILER_EXPECTED=93
5+
SCALA_SCALA_LIBRARY_EXPECTED=99
6+
SCALA_SCALA_COMPILER_EXPECTED=95
77
DOTTY_COMPILER_EXPECTED=83
88
SYNTAX_COMPLEXITY_CEILING=1300
99

0 commit comments

Comments
 (0)