Skip to content

Commit

Permalink
Merge pull request #222 from susliko/derives-clause
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored May 24, 2023
2 parents 9cb4266 + c34e34e commit c4f0634
Show file tree
Hide file tree
Showing 5 changed files with 723,494 additions and 719,448 deletions.
33 changes: 33 additions & 0 deletions corpus/definitions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,22 @@ object O3 extends A {
(type_identifier))
(template_body)))

================================================================================
Object definitions
================================================================================
case object A extends B derives C, D {}
--------------------------------------------------------------------------------

(compilation_unit
(object_definition
(identifier)
(extends_clause
(type_identifier))
(derives_clause
(type_identifier)
(type_identifier))
(template_body)))

================================================================================
Class definitions
================================================================================
Expand All @@ -439,6 +455,23 @@ class C[
(identifier))
(template_body)))

================================================================================
Class definitions (Scala 3)
================================================================================
final case class C() extends A derives B, C
--------------------------------------------------------------------------------

(compilation_unit
(class_definition
(modifiers)
(identifier)
(class_parameters)
(extends_clause
(type_identifier))
(derives_clause
(type_identifier)
(type_identifier))))

================================================================================
Subclass definitions
================================================================================
Expand Down
12 changes: 9 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ module.exports = grammar({
_object_definition: $ => prec.left(seq(
field('name', $._identifier),
field('extend', optional($.extends_clause)),
field('derive', optional($.derives_clause)),
field('body', optional($.template_body)),
)),

Expand All @@ -263,10 +264,15 @@ module.exports = grammar({
optional($.modifiers),
optional('case'),
'class',
$._class_definition,
)),

_class_definition: $ => seq(
$._class_constructor,
field('extend', optional($.extends_clause)),
field('derive', optional($.derives_clause)),
field('body', optional($.template_body))
)),
),

/**
* ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
Expand Down Expand Up @@ -610,10 +616,10 @@ module.exports = grammar({
optional($.arguments)
)),

derives_clause: $ => seq(
derives_clause: $ => prec.left(seq(
'derives',
commaSep1(field('type', $._type_identifier))
),
)),

class_parameters: $ => prec(1, seq(
'(',
Expand Down
Loading

0 comments on commit c4f0634

Please sign in to comment.