From 0c79e84739ab498faddd28454a2b30cc5408b969 Mon Sep 17 00:00:00 2001 From: Nicolas PENELOUX Date: Tue, 24 Oct 2023 21:22:02 +0200 Subject: [PATCH] Trying to fix Sequence --- flap/src/hopix/hopixParser.mly | 54 +++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index 80e38e5..1337846 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -44,6 +44,7 @@ %left PLUS MINUS %left SLASH STAR +%left ref1 %left fun1 %left app1 @@ -174,7 +175,6 @@ simple_pattern: match l with | [alone] -> Position.value alone | _ -> PTuple(l) } - /* Annotation de type */ | p=located(simple_pattern) COLON ty=located(ty) { PTypeAnnotation(p, ty) @@ -288,10 +288,16 @@ simple_expression: | i=located(var_identifier) tl=option(type_list) { Variable(i, tl) } +| LPAREN e=located(expression) COLON t=located(ty) RPAREN { + TypeAnnotation(e, t) + } /* Tagged Value - Construction d'une donnée */ +/* | const=located(constructor) tl=option(type_list) el=optionlist(expr_list) { Tagged(const, tl, el) } + */ + /* Tuple n = 0 - Construction d'un 0-uplet */ | LPAREN RPAREN { Tuple([]) @@ -310,7 +316,7 @@ simple_expression: } /* Lecture de variable * !expr */ -| EXCLA e=located(simple_expression) { +| EXCLA e=located(simple_expression){ Read(e) } @@ -324,20 +330,50 @@ expr_list: el } +mid_expression: +|e=simple_expression{ + e +} +/* Parenthésage */ +| LPAREN e=expression RPAREN { + e + } + +/* Field record */ +| e=located(mid_expression) DOT l=located(label_identifier) tl=option(type_list) { + Field(e, l, tl) + } + +/* Application */ +| e1=located(mid_expression) e2=located(mid_expression) %prec app1 { + Apply(e1, e2) + } + +| const=located(constructor) tl=option(type_list) el=optionlist(expr_list) { + Tagged(const, tl, el) + } + expression: -| e=simple_expression { +| e=mid_expression { e } /* Field - Projection d’un champ */ +/* | e=located(expression) DOT l=located(label_identifier) tl=option(type_list) { Field(e, l, tl) } /* 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)) { + + /* +| e=located(mid_expression) + SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(mid_expression)) { Sequence(e :: e_list) - } + }*/ + +| e=located(expression) SEMICOLON e2=located(expression){ + Sequence([e;e2]) +} /* | e1=located(expression) SEMICOLON e2=located(expression) { Sequence([e1; e2]) } */ @@ -350,6 +386,7 @@ expression: Fun(FunctionDefinition(p, e)) } /* Application */ +/* | e1=located(expression) e2=located(expression) %prec app1 { Apply(e1, e2) } @@ -430,11 +467,14 @@ expression: } /* Parenthésage * Pas sûr mais je vois pas sinon */ + + /* | LPAREN e=expression RPAREN { e - } + }*/ /* Annotation de type * (e : ty) */ + /* | LPAREN e=located(expression) COLON t=located(ty) RPAREN { TypeAnnotation(e, t) }