COLON type_scheme

This commit is contained in:
Mylloon 2023-10-24 14:34:37 +02:00
parent 5f48faa278
commit 9566754c75
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -80,7 +80,7 @@ definition:
DefineType (tc, tvl, Abstract) DefineType (tc, tvl, Abstract)
} }
/* Valeurs externes */ /* Valeurs externes */
| EXTERN id=located(identifier) ts=located(type_scheme) { | EXTERN id=located(identifier) COLON ts=located(type_scheme) {
DeclareExtern(id, ts) DeclareExtern(id, ts)
} }
/* Définition de valeurs */ /* Définition de valeurs */
@ -126,7 +126,7 @@ label_with_type:
vdefinition: vdefinition:
/* Valeur simple */ /* Valeur simple */
| LET i=located(identifier) ts=option(vdef_type_scheme) | LET i=located(identifier) ts=option(colon_type_scheme)
EQUAL e=located(expression) %prec let1{ EQUAL e=located(expression) %prec let1{
SimpleValue(i, ts, e) SimpleValue(i, ts, e)
} }
@ -138,20 +138,12 @@ vdefinition:
RecFunctions(fl) RecFunctions(fl)
} }
vdef_type_scheme:
| COLON ts=located(type_scheme) {
ts
}
fundef: fundef:
| COLON t=option(located(type_scheme)) i=located(identifier) p=located(pattern) | t=option(colon_type_scheme) i=located(identifier) p=located(pattern)
EQUAL e=located(expression) %prec fun1 { EQUAL e=located(expression) %prec fun1 {
i, t, FunctionDefinition(p, e) i, t, FunctionDefinition(p, e)
} }
| i=located(identifier) p=located(pattern) EQUAL e=located(expression) {
i, None, FunctionDefinition(p, e)
}
/********************************** PATTERN ***********************************/ /********************************** PATTERN ***********************************/
@ -275,15 +267,19 @@ ty:
type_scheme: type_scheme:
/* Il faut peut être modifié le séparateur */ | LBRACK liste_typevar=separated_list(COMMA, located(type_variable))
| COLON LBRACK liste_typevar=separated_list(COMMA, located(type_variable))
RBRACK ty=located(ty) { RBRACK ty=located(ty) {
ForallTy(liste_typevar, ty) ForallTy(liste_typevar, ty)
} }
| COLON ty=located(ty) { | ty=located(ty) {
ForallTy([], ty) ForallTy([], ty)
} }
colon_type_scheme:
| COLON ts=located(type_scheme) {
ts
}
/********************************* EXPRESSION *********************************/ /********************************* EXPRESSION *********************************/