Skip to content

Commit 9d7125f

Browse files
committed
support polymorphic type and locally abstract type
Close rescript-lang#163
1 parent 41f0b28 commit 9d7125f

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

grammar.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ module.exports = grammar({
320320
$.unit_type,
321321
$.module_pack,
322322
$.unit,
323+
$.polymorphic_type,
324+
),
325+
326+
polymorphic_type: $ => seq(
327+
choice(repeat1($.type_identifier), $.abstract_type),
328+
'.',
329+
$._inline_type
323330
),
324331

325332
tuple_type: $ => prec.dynamic(-1, seq(
@@ -808,7 +815,7 @@ module.exports = grammar({
808815
$._pattern,
809816
$.labeled_parameter,
810817
$.unit,
811-
$.type_parameter,
818+
$.abstract_type
812819
),
813820
),
814821

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

823-
type_parameter: $ => seq(
830+
abstract_type: $ => seq(
824831
'type',
825832
repeat1($.type_identifier),
826833
),

test/corpus/functions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Type annotations
7979
body: (number))))
8080

8181
===================================================
82-
Type arguments
82+
Abstract type
8383
===================================================
8484

8585
let foo = (type a, x: 'a): a => x
@@ -91,7 +91,7 @@ let foo = (type a, x: 'a): a => x
9191
(value_identifier)
9292
(function
9393
(formal_parameters
94-
(parameter (type_parameter (type_identifier)))
94+
(parameter (abstract_type (type_identifier)))
9595
(parameter
9696
(value_identifier)
9797
(type_annotation (type_identifier))))

test/corpus/type_declarations.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,46 @@ type test = (. ~attr: string) => unit
439439
(type_identifier)))))
440440
(unit_type))))
441441

442+
===========================================
443+
Polymorphic type
444+
===========================================
445+
446+
let id: 'a. 'a => 'a = x => x
447+
448+
let add: type a. (number<a>, number<a>) => a
449+
450+
---
451+
452+
(source_file
453+
(let_binding
454+
(value_identifier)
455+
(type_annotation
456+
(polymorphic_type
457+
(type_identifier)
458+
(function_type
459+
(function_type_parameters (type_identifier))
460+
(type_identifier))))
461+
(function
462+
(value_identifier)
463+
(value_identifier)))
464+
465+
(let_binding
466+
(value_identifier)
467+
(type_annotation
468+
(polymorphic_type
469+
(abstract_type (type_identifier))
470+
(function_type
471+
(function_type_parameters
472+
(parameter
473+
(generic_type
474+
(type_identifier)
475+
(type_arguments (type_identifier))))
476+
(parameter
477+
(generic_type
478+
(type_identifier)
479+
(type_arguments
480+
(type_identifier))))) (type_identifier))))))
481+
442482
===========================================
443483
Variance annotations
444484
===========================================

0 commit comments

Comments
 (0)