Skip to content
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
11 changes: 9 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ module.exports = grammar({
$.unit_type,
$.module_pack,
$.unit,
$.polymorphic_type,
),

polymorphic_type: $ => seq(
choice(repeat1($.type_identifier), $.abstract_type),
'.',
$._inline_type
),

tuple_type: $ => prec.dynamic(-1, seq(
Expand Down Expand Up @@ -808,7 +815,7 @@ module.exports = grammar({
$._pattern,
$.labeled_parameter,
$.unit,
$.type_parameter,
$.abstract_type
),
),

Expand All @@ -820,7 +827,7 @@ module.exports = grammar({
optional(field('default_value', $._labeled_parameter_default_value)),
),

type_parameter: $ => seq(
abstract_type: $ => seq(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming because there is a rule with similar name type_parameters.

In OCaml it is astract_type

'type',
repeat1($.type_identifier),
),
Expand Down
4 changes: 2 additions & 2 deletions test/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Type annotations
body: (number))))

===================================================
Type arguments
Abstract type
===================================================

let foo = (type a, x: 'a): a => x
Expand All @@ -91,7 +91,7 @@ let foo = (type a, x: 'a): a => x
(value_identifier)
(function
(formal_parameters
(parameter (type_parameter (type_identifier)))
(parameter (abstract_type (type_identifier)))
(parameter
(value_identifier)
(type_annotation (type_identifier))))
Expand Down
40 changes: 40 additions & 0 deletions test/corpus/type_declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,46 @@ type test = (. ~attr: string) => unit
(type_identifier)))))
(unit_type))))

===========================================
Polymorphic type
===========================================

let id: 'a. 'a => 'a = x => x

let add: type a. (number<a>, number<a>) => a

---

(source_file
(let_binding
(value_identifier)
(type_annotation
(polymorphic_type
(type_identifier)
(function_type
(function_type_parameters (type_identifier))
(type_identifier))))
(function
(value_identifier)
(value_identifier)))

(let_binding
(value_identifier)
(type_annotation
(polymorphic_type
(abstract_type (type_identifier))
(function_type
(function_type_parameters
(parameter
(generic_type
(type_identifier)
(type_arguments (type_identifier))))
(parameter
(generic_type
(type_identifier)
(type_arguments
(type_identifier))))) (type_identifier))))))

===========================================
Variance annotations
===========================================
Expand Down