File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ module.exports = grammar({
269269 choice ( '=' , '+=' ) ,
270270 optional ( 'private' ) ,
271271 $ . _type ,
272+ repeat ( $ . type_constraint ) ,
272273 optional ( seq ( '=' , $ . _type ) ) ,
273274 repeat ( alias ( $ . _type_declaration_and , $ . type_declaration ) ) ,
274275 ) ) ,
@@ -322,6 +323,13 @@ module.exports = grammar({
322323 $ . unit ,
323324 ) ,
324325
326+ type_constraint : $ => seq (
327+ 'constraint' ,
328+ $ . _type ,
329+ '=' ,
330+ $ . _type
331+ ) ,
332+
325333 tuple_type : $ => prec . dynamic ( - 1 , seq (
326334 '(' ,
327335 commaSep1t ( $ . _type ) ,
Original file line number Diff line number Diff line change @@ -455,3 +455,34 @@ type t<-'a>
455455 (type_declaration
456456 (type_identifier)
457457 (type_parameters (type_identifier))))
458+
459+ ===========================================
460+ Type constraint
461+ ===========================================
462+
463+ type t<'a> = 'a constraint 'a = int
464+ type decorator<'a, 'b> = 'a => 'b constraint 'a = int constraint 'b = _ => _
465+
466+ ---
467+
468+ (source_file
469+ (type_declaration
470+ (type_identifier)
471+ (type_parameters (type_identifier))
472+ (type_identifier)
473+ (type_constraint
474+ (type_identifier) (type_identifier)))
475+
476+ (type_declaration
477+ (type_identifier)
478+ (type_parameters (type_identifier) (type_identifier))
479+ (function_type
480+ (function_type_parameters (type_identifier))
481+ (type_identifier))
482+ (type_constraint
483+ (type_identifier) (type_identifier))
484+ (type_constraint
485+ (type_identifier)
486+ (function_type
487+ (function_type_parameters (type_identifier))
488+ (type_identifier)))))
You can’t perform that action at this time.
0 commit comments