fix POr et PAnd, continuation d'expression
This commit is contained in:
parent
d1cdc273bd
commit
648076bb3e
2 changed files with 73 additions and 18 deletions
|
@ -94,6 +94,7 @@ rule token = parse
|
|||
| '}' { RBRACE }
|
||||
| '_' { WILDCARD }
|
||||
| ':' { COLON }
|
||||
| ';' { SEMICOLON}
|
||||
| "->" { ARROW }
|
||||
| '<' { INFERIOR }
|
||||
| '>' { SUPERIOR }
|
||||
|
@ -102,6 +103,7 @@ rule token = parse
|
|||
| '*' { STAR }
|
||||
| ',' { COMMA }
|
||||
| '.' { DOT }
|
||||
| '\\' {BACKSLASH }
|
||||
|
||||
(** Strings *)
|
||||
| '"' { read_string (Buffer.create 16) lexbuf }
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
%token EOF LET TYPE WILDCARD STAR ARROW COLON EXTERN FUN COMMA AND EQUAL LPAREN
|
||||
%token RPAREN LBRACK RBRACK LBRACE RBRACE INFERIOR SUPERIOR BINOP DO ELSE FOR
|
||||
%token FROM IF MATCH PIPE REF THEN TO UNTIL WHILE AND_KW DOT
|
||||
%token FROM IF MATCH PIPE REF THEN TO UNTIL WHILE AND_KW DOT SEMICOLON BACKSLASH
|
||||
|
||||
%token<Mint.t> INT
|
||||
%token<string> ID TID CID STRING
|
||||
|
@ -94,7 +94,22 @@ fundef:
|
|||
/* à revoir éventuellement : PTaggedValue (et PRecord) est réécrite 4 fois, mais
|
||||
* peut être qu'en utilisant des option, on pourrait diminuer le nombre de répétition.
|
||||
* TODO : y'a environ 50 warnings ici, surtout au niveau du POr et PAnd */
|
||||
pattern:
|
||||
|
||||
branches:
|
||||
| b=separated_nonempty_list(PIPE,located(branch)){
|
||||
b
|
||||
}
|
||||
| PIPE b = separated_nonempty_list(PIPE,located(branch)){
|
||||
b
|
||||
}
|
||||
|
||||
branch:
|
||||
| p = located(pattern) ARROW e=located(expression){
|
||||
Branch(p,e)
|
||||
}
|
||||
|
||||
|
||||
simple_pattern:
|
||||
/* Parenthésage */
|
||||
| LPAREN p=pattern RPAREN {
|
||||
p
|
||||
|
@ -108,7 +123,7 @@ pattern:
|
|||
PWildcard
|
||||
}
|
||||
/* Annotation de type */
|
||||
| p=located(pattern) COLON ty=located(ty) {
|
||||
| p=located(simple_pattern) COLON ty=located(ty) {
|
||||
PTypeAnnotation(p,ty)
|
||||
}
|
||||
/* Entier / Caractère / String */
|
||||
|
@ -140,16 +155,23 @@ pattern:
|
|||
PRecord(l, liste_ty)
|
||||
}
|
||||
/* Disjonction */
|
||||
/*
|
||||
| p1=located(pattern) PIPE p_list=separated_nonempty_list(PIPE, located(pattern)) {
|
||||
|
||||
pattern:
|
||||
| p1=pattern_and{
|
||||
p1
|
||||
}
|
||||
| p1=located(pattern_and) PIPE p_list=separated_nonempty_list(PIPE, located(pattern_and)) {
|
||||
POr(p1 :: p_list)
|
||||
}
|
||||
/* Conjonction */
|
||||
/*
|
||||
| p1=located(pattern) AND p_list=separated_nonempty_list(AND, located(pattern)) {
|
||||
pattern_and:
|
||||
| p1=simple_pattern{
|
||||
p1
|
||||
}
|
||||
| p1=located(simple_pattern) AND p_list=separated_nonempty_list(AND, located(simple_pattern)) {
|
||||
PAnd(p1 :: p_list)
|
||||
}
|
||||
*/
|
||||
|
||||
pattern_list:
|
||||
/* N-uplets */
|
||||
| LPAREN p=separated_nonempty_list(COMMA, pattern) RPAREN {
|
||||
|
@ -214,7 +236,7 @@ type_scheme:
|
|||
/* De manière générale, il faudrait au mieux revoir le code, pour le factoriser et le rendre plus propre */
|
||||
/* (il y a même moyen que ça le soit obligatoire pour pas avoir des conflits éventuel) */
|
||||
/* Exemple : TAgged et Record, trop de cas différent alors qu'on pourrait en faire en 2 fois au moins voir 1 */
|
||||
expression:
|
||||
simple_expression:
|
||||
/* Simple litteral */
|
||||
| l=located(literal) {
|
||||
Literal l
|
||||
|
@ -230,6 +252,14 @@ expression:
|
|||
Variable(i,t_list)
|
||||
}
|
||||
|
||||
/* Tuple n = 0 and n > 1 */
|
||||
| LPAREN RPAREN {
|
||||
Tuple([])
|
||||
}
|
||||
| LPAREN e=located(expression) COMMA e_list = separated_nonempty_list(COMMA,located(expression)) RPAREN {
|
||||
Tuple(e::e_list)
|
||||
}
|
||||
|
||||
/* Tagged Value*/
|
||||
/* K */
|
||||
| const = located(constructor){
|
||||
|
@ -252,14 +282,6 @@ expression:
|
|||
Tagged(const,t_list,e_list)
|
||||
}
|
||||
|
||||
/* Tuple n = 0 and n > 1 */
|
||||
| LPAREN RPAREN {
|
||||
Tuple([])
|
||||
}
|
||||
| LPAREN e=located(expression) COMMA e_list = separated_nonempty_list(COMMA,located(expression)) RPAREN {
|
||||
Tuple(e::e_list)
|
||||
}
|
||||
|
||||
/* Record */
|
||||
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE {
|
||||
Record(l, None)
|
||||
|
@ -271,6 +293,15 @@ expression:
|
|||
Record(l, t_list)
|
||||
}
|
||||
|
||||
|
||||
|
||||
expression:
|
||||
| e=simple_expression{
|
||||
e
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Field */
|
||||
|
||||
/* e.l */
|
||||
|
@ -285,6 +316,28 @@ expression:
|
|||
| e = located(expression) DOT l=located(label) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR {
|
||||
Field(e,l,t_list)
|
||||
}
|
||||
/* Sequence */
|
||||
/* Pas sûr, voir s'il ne fuat 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)
|
||||
}
|
||||
|
||||
/* Definition locale */
|
||||
| vd= vdefinition SEMICOLON e=located(expression){
|
||||
Define(vd,e)
|
||||
}
|
||||
|
||||
/* Fonction anonyme */
|
||||
| BACKSLASH p=located(pattern) ARROW e=located(expression){
|
||||
Fun(FunctionDefinition(p,e))
|
||||
}
|
||||
|
||||
/* Application */
|
||||
| e1=located(expression) e2=located(expression){
|
||||
Apply(e1,e2)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************** BASIC TYPES *********************************/
|
||||
|
|
Reference in a new issue