Structural types in declarations

Problem
-------
Structural types in declarations are not parsed:
```
val x: F { val y: Int }
```

Solution
-------
Remove -1 precedence for `$._structural_type` branch of  `$.compount_type`, resolve conflict with `$._type` explicitly

Extra changes
-------
Removed some unused conflict resolutions
text_sliders
susliko 2023-06-10 15:40:51 +07:00
parent d42d40c7ad
commit bc9fb988bf
3 changed files with 23 additions and 14 deletions

@ -201,6 +201,8 @@ type G = H[A1] {
type I = F1[A1: type I = F1[A1:
def foo: A2] def foo: A2]
def a: F { val x: Int } = ???
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(compilation_unit (compilation_unit
@ -249,7 +251,16 @@ type I = F1[A1:
(refinement (refinement
(function_declaration (function_declaration
(identifier) (identifier)
(type_identifier)))))))) (type_identifier)))))))
(function_definition
(identifier)
(compound_type
(type_identifier)
(refinement
(val_declaration
(identifier)
(type_identifier))))
(operator_identifier)))
================================================================================ ================================================================================
Infix types Infix types

@ -65,16 +65,11 @@ module.exports = grammar({
conflicts: $ => [ conflicts: $ => [
[$.tuple_type, $.parameter_types], [$.tuple_type, $.parameter_types],
[$.binding, $._simple_expression], [$.binding, $._simple_expression],
[$.binding, $.ascription_expression],
[$.binding, $._type_identifier], [$.binding, $._type_identifier],
[$.if_expression, $.expression],
[$.while_expression, $._simple_expression], [$.while_expression, $._simple_expression],
[$.for_expression, $.infix_expression],
[$._indentable_expression, $.do_while_expression],
[$.if_expression], [$.if_expression],
[$.match_expression], [$.match_expression],
[$._function_constructor, $._type_identifier], [$._function_constructor, $._type_identifier],
[$._type_identifier, $.identifier],
[$.instance_expression], [$.instance_expression],
// In case of: 'extension' _indent '{' 'case' operator_identifier 'if' operator_identifier • '=>' … // In case of: 'extension' _indent '{' 'case' operator_identifier 'if' operator_identifier • '=>' …
// we treat `operator_identifier` as `simple_expression` // we treat `operator_identifier` as `simple_expression`
@ -91,7 +86,10 @@ module.exports = grammar({
[$._full_enum_def], [$._full_enum_def],
// _start_val identifier ',' identifier • ':' … // _start_val identifier ',' identifier • ':' …
[$.identifiers, $.val_declaration], [$.identifiers, $.val_declaration],
// 'enum' operator_identifier _automatic_semicolon '(' ')' • ':' …
[$.class_parameters], [$.class_parameters],
// 'for' operator_identifier ':' _annotated_type • ':' …
[$._type, $.compound_type]
], ],
word: $ => $._alpha_identifier, word: $ => $._alpha_identifier,
@ -375,19 +373,19 @@ module.exports = grammar({
*/ */
template_body: $ => template_body: $ =>
choice( choice(
prec.left(PREC.control, $._indented_template_body), $._indented_template_body,
prec.left(PREC.control, $._braced_template_body), $._braced_template_body,
), ),
_indented_template_body: $ => _indented_template_body: $ =>
seq(":", $._indent, optional($.self_type), $._block, $._outdent), prec.left(PREC.control, seq(":", $._indent, optional($.self_type), $._block, $._outdent)),
_braced_template_body: $ => _braced_template_body: $ =>
seq( prec.left(PREC.control, seq(
"{", "{",
optional(choice($._braced_template_body1, $._braced_template_body2)), optional(choice($._braced_template_body1, $._braced_template_body2)),
"}", "}",
), )),
_braced_template_body1: $ => seq(optional($.self_type), $._block), _braced_template_body1: $ => seq(optional($.self_type), $._block),
_braced_template_body2: $ => _braced_template_body2: $ =>
@ -812,7 +810,7 @@ module.exports = grammar({
repeat1(seq("with", field("extra", $._annotated_type))), repeat1(seq("with", field("extra", $._annotated_type))),
), ),
), ),
prec.left(-1, seq(field("base", $._annotated_type), $._refinement)), prec.left(seq(field("base", $._annotated_type), $._refinement)),
prec.left( prec.left(
-1, -1,
seq( seq(

@ -2,8 +2,8 @@
# This is an integration test to generally check the quality of parsing. # This is an integration test to generally check the quality of parsing.
SCALA_SCALA_LIBRARY_EXPECTED=98 SCALA_SCALA_LIBRARY_EXPECTED=99
SCALA_SCALA_COMPILER_EXPECTED=93 SCALA_SCALA_COMPILER_EXPECTED=95
DOTTY_COMPILER_EXPECTED=83 DOTTY_COMPILER_EXPECTED=83
SYNTAX_COMPLEXITY_CEILING=1300 SYNTAX_COMPLEXITY_CEILING=1300