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 FUN
%left STRING
%left STRING
%left INT CID CHAR WHILE
%left ID
%right REF DO
%right REF DO
%left LET MATCH IF FOR
%right ARROW
%right SEMICOLON
%right ARROW
%right SEMICOLON
%left DOT
%left ASSIGN
%left ASSIGN
%left LBRACE
%left BACKSLASH
%left EXCLA COLON
%left EXCLA COLON
/* priorités binop */
@ -80,7 +80,7 @@ definition:
DefineType (tc, tvl, Abstract)
}
/* Valeurs externes */
| EXTERN id=located(identifier) ts=located(type_scheme) {
| EXTERN id=located(identifier) COLON ts=located(type_scheme) {
DeclareExtern(id, ts)
}
/* Définition de valeurs */
@ -126,9 +126,9 @@ label_with_type:
vdefinition:
/* 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{
SimpleValue(i, ts, e)
SimpleValue(i, ts, e)
}
/* Fonction(s)
* Exemple :
@ -138,20 +138,12 @@ vdefinition:
RecFunctions(fl)
}
vdef_type_scheme:
| COLON ts=located(type_scheme) {
ts
}
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 {
i, t, FunctionDefinition(p, e)
}
| i=located(identifier) p=located(pattern) EQUAL e=located(expression) {
i, None, FunctionDefinition(p, e)
}
/********************************** PATTERN ***********************************/
@ -275,15 +267,19 @@ ty:
type_scheme:
/* Il faut peut être modifié le séparateur */
| COLON LBRACK liste_typevar=separated_list(COMMA, located(type_variable))
| LBRACK liste_typevar=separated_list(COMMA, located(type_variable))
RBRACK ty=located(ty) {
ForallTy(liste_typevar, ty)
}
| COLON ty=located(ty) {
| ty=located(ty) {
ForallTy([], ty)
}
colon_type_scheme:
| COLON ts=located(type_scheme) {
ts
}
/********************************* EXPRESSION *********************************/
@ -342,7 +338,7 @@ expression:
}
/* Sequence - Séquencement *
* Pas sûr, voir s'il ne faut pas une troisième couche d'expression */
| e=located(simple_expression)
SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) {
Sequence(e :: e_list)
@ -364,7 +360,7 @@ expression:
| e1=located(expression) e2=located(expression) {
Apply(e1, e2)
}
/* Operateurs binaires - Application infixe */
| e1=located(expression) b=binop e2=located(expression) {
Apply(