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

@ -26,21 +26,21 @@
%left let1 %left let1
%left FUN %left FUN
%left STRING %left STRING
%left INT CID CHAR WHILE %left INT CID CHAR WHILE
%left ID %left ID
%right REF DO %right REF DO
%left LET MATCH IF FOR %left LET MATCH IF FOR
%right ARROW %right ARROW
%right SEMICOLON %right SEMICOLON
%left DOT %left DOT
%left ASSIGN %left ASSIGN
%left LBRACE %left LBRACE
%left BACKSLASH %left BACKSLASH
%left EXCLA COLON %left EXCLA COLON
/* priorités binop */ /* priorités binop */
@ -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,9 +126,9 @@ 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)
} }
/* Fonction(s) /* Fonction(s)
* Exemple : * Exemple :
@ -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 *********************************/
@ -342,7 +338,7 @@ expression:
} }
/* Sequence - Séquencement * /* Sequence - Séquencement *
* Pas sûr, voir s'il ne faut pas une troisième couche d'expression */ * Pas sûr, voir s'il ne faut pas une troisième couche d'expression */
| e=located(simple_expression) | e=located(simple_expression)
SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) { SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) {
Sequence(e :: e_list) Sequence(e :: e_list)
@ -364,7 +360,7 @@ expression:
| e1=located(expression) e2=located(expression) { | e1=located(expression) e2=located(expression) {
Apply(e1, e2) Apply(e1, e2)
} }
/* Operateurs binaires - Application infixe */ /* Operateurs binaires - Application infixe */
| e1=located(expression) b=binop e2=located(expression) { | e1=located(expression) b=binop e2=located(expression) {
Apply( Apply(