diff --git a/grammar.js b/grammar.js index bf63804..53b1f5f 100644 --- a/grammar.js +++ b/grammar.js @@ -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( @@ -808,7 +815,7 @@ module.exports = grammar({ $._pattern, $.labeled_parameter, $.unit, - $.type_parameter, + $.abstract_type ), ), @@ -820,7 +827,7 @@ module.exports = grammar({ optional(field('default_value', $._labeled_parameter_default_value)), ), - type_parameter: $ => seq( + abstract_type: $ => seq( 'type', repeat1($.type_identifier), ), diff --git a/test/corpus/functions.txt b/test/corpus/functions.txt index d8112d8..e58cfe7 100644 --- a/test/corpus/functions.txt +++ b/test/corpus/functions.txt @@ -79,7 +79,7 @@ Type annotations body: (number)))) =================================================== -Type arguments +Abstract type =================================================== let foo = (type a, x: 'a): a => x @@ -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)))) diff --git a/test/corpus/type_declarations.txt b/test/corpus/type_declarations.txt index 82a3b48..454f2f1 100644 --- a/test/corpus/type_declarations.txt +++ b/test/corpus/type_declarations.txt @@ -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, number) => 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 ===========================================