From f11c33ff18f2b688122d4f1f451af9a283f9cbbe Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 17 Oct 2023 11:49:13 +0200 Subject: [PATCH] format --- flap/src/hopix/hopixLexer.mll | 94 ++++++++++++++-------------- flap/src/hopix/hopixParser.mly | 110 +++++++++++++++++---------------- 2 files changed, 104 insertions(+), 100 deletions(-) diff --git a/flap/src/hopix/hopixLexer.mll b/flap/src/hopix/hopixLexer.mll index 2f02e21..f8a4112 100644 --- a/flap/src/hopix/hopixLexer.mll +++ b/flap/src/hopix/hopixLexer.mll @@ -10,8 +10,6 @@ let error lexbuf = error "during lexing" (lex_join lexbuf.lex_start_p lexbuf.lex_curr_p) - - } let newline = ('\010' | '\013' | "\013\010") @@ -28,76 +26,76 @@ let integers = '-'? (digit+ | octa+) let printable = [' ' '\t' '\n' '\r' (*33-126*)] (*pas sûr*) -let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']* +let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']* let constr_id = ['A'-'Z']['A'-'Z' 'a'-'z' '0'-'9' '_']* let type_variable = ['\'']['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']* -(* On ne peut pas différencier au niveau du lexer var_id label_id et type_con, il faudra le faire à l'analyseur syntaxique*) +(* On ne peut pas différencier au niveau du lexer var_id label_id et type_con, + * il faudra le faire à l'analyseur syntaxique *) let atom = '"' let char = ['\'']atom['\''] let string = ['\"']((atom | '\'' | "\\\""))['\"'] -(*let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"?"*) +(* let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"?" *) rule token = parse (** Layout *) - | newline { next_line_and token lexbuf } - | blank+ { token lexbuf } - | eof { EOF } + | newline { next_line_and token lexbuf } + | blank+ { token lexbuf } + | eof { EOF } | "{*" { commentary lexbuf; token lexbuf } - | "##" {commentary_line lexbuf} + | "##" { commentary_line lexbuf } (** Keywords *) - | "let" { LET } - | "type" { TYPE } - | "extern" { EXTERN } - | "fun" { FUN } - | "match" { MATCH } - | "if" { IF } - | "then" { THEN } - | "else" { ELSE } - | "ref" { REF } - | "while" { WHILE } - | "do" { DO } - | "until" { UNTIL } - | "for" { FOR } - | "from" { FROM } - | "to" { TO } - | "and" { AND } - | "for" { FOR } - (* Fini ? *) + | "let" { LET } + | "type" { TYPE } + | "extern" { EXTERN } + | "fun" { FUN } + | "match" { MATCH } + | "if" { IF } + | "then" { THEN } + | "else" { ELSE } + | "ref" { REF } + | "while" { WHILE } + | "do" { DO } + | "until" { UNTIL } + | "for" { FOR } + | "from" { FROM } + | "to" { TO } + | "and" { AND } + | "for" { FOR } + (* Fini ? *) + + (** Binar operation : pas sûr pour celui là*) + (* | binop as b { BINOP (* TODO *) } *) - (* binar operation : pas sûr pour celui là*) - (* - | binop as b { BINOP (* TODO *) } -*) (** Operators *) - | '=' { EQUAL } + (* | '=' { EQUAL } *) (* ponctuation *) - | '(' { LPAREN } - | ')' { RPAREN } - | '[' { LBRACK } - | ']' { RBRACK } - | '_' { WILDCARD } - | ':' { DPOINT } - | "->" { ARROW } - | "<" { INFERIOR } - | ">" { SUPERIOR } + | '(' { LPAREN } + | ')' { RPAREN } + | '[' { LBRACK } + | ']' { RBRACK } + | '_' { WILDCARD } + | ':' { DPOINT } + | "->" { ARROW } + | "<" { INFERIOR } + | ">" { SUPERIOR } (** Values *) - | integers as i { INT (Mint.of_string i) } - | ident as s { ID s } + | integers as i { INT (Mint.of_string i) } + | ident as s { ID s } (** Lexing error *) | _ { error lexbuf "unexpected character." } - and commentary = parse - | "*}" { () } + and commentary = parse + | "*}" { () } | "{*" { commentary lexbuf; commentary lexbuf } - | _ { commentary lexbuf } + | _ { commentary lexbuf } - and commentary_line = parse + and commentary_line = parse | '\n' { next_line_and token lexbuf } - | _ { commentary_line lexbuf } + | _ { commentary_line lexbuf } diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index 4dcdd8f..666b13e 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -19,86 +19,89 @@ program: definition } + definition: | v=vdefinition { DefineValue v } -vdefinition: // manque le type ici, on met None en attendant + +vdefinition: +// manque le type ici, on met None en attendant | LET i=located(identifier) EQUAL e=located(expression) { SimpleValue(i, None, e) - }(* -| LET i=located(identifier) DPOINT ts=located(type_scheme) EQUAL e=located(expression){ - SimpleValue(i,ts,e) -}*) - (* marche pas*) - + } +/* // marche pas +| LET i=located(identifier) DPOINT ts=located(type_scheme) EQUAL e=located(expression) { + SimpleValue(i,ts,e) + } */ +/* fun : int f a = 1 */ | FUN f=fundef { - RecFunctions([f]) -} -(*fun : int f a = 1*) + RecFunctions([f]) + } -(* de même*) + +/* de même */ fundef: -|(*ts est temp*) i=located(identifier) p=pattern EQUAL e=located(expression){ - FunctionDefinition(p,e) -} -|(*ts est temp*) DPOINT ts=located(type_scheme) i=located(identifier) p=pattern EQUAL e=located(expression){ - FunctionDefinition(p,e) -} +/* ts est temp */ +| i=located(identifier) p=pattern EQUAL e=located(expression) { + FunctionDefinition(p, e) + } +/* ts est temp */ +| DPOINT ts=located(type_scheme) i=located(identifier) p=pattern EQUAL e=located(expression) { + FunctionDefinition(p, e) + } pattern: -| i=located(identifier){ - PVariable i -} +| i=located(identifier) { + PVariable i + } | WILDCARD { - PWildcard -} - + PWildcard + } ty: -| tc = type_constructor{ - TyCon(tc,None) -} +| tc = type_constructor { + TyCon(tc, None) + } (* Todo version avec l'optionnel*) - -| ty1=located(ty) ARROW ty2=located(ty){ - TyArrow(ty1,ty2) -} -| ty1=located(ty) STAR ty2=located(ty){ - TyTuple([ty1;ty2]) -} -| ty1=located(ty) STAR ty2= located(ty) STAR liste_ty = separated_list(STAR,located(ty)){ - TyTuple(ty1::ty2::liste_ty) -} -| LPAREN type_var=type_variable RPAREN { - TyVar type_var -} - - type_scheme: - (* il faut peut être modifié le séparateur*) - | LBRACK liste_typevar = separated_list(COMMA,located(type_variable)) RBRACK ty=located(ty){ - ForallTy(liste_typevar,ty) +| ty1=located(ty) ARROW ty2=located(ty) { + TyArrow(ty1, ty2) } - | ty=located(ty){ - ForallTy([],ty) +| ty1=located(ty) STAR ty2=located(ty) { + TyTuple([ty1; ty2]) + } +| ty1=located(ty) STAR ty2=located(ty) STAR liste_ty = separated_list(STAR,located(ty)) { + TyTuple(ty1::ty2::liste_ty) + } +| LPAREN type_var=type_variable RPAREN { + TyVar type_var + } + + +type_scheme: +(* il faut peut être modifié le séparateur*) +| LBRACK liste_typevar=separated_list(COMMA,located(type_variable)) RBRACK ty=located(ty) { + ForallTy(liste_typevar, ty) + } +| ty=located(ty) { + ForallTy([], ty) } type_variable: | tid=TID { - TId tid -} + TId tid + } + type_constructor: | tcon = TID { - TCon tcon -} - - + TCon tcon + } expression: @@ -106,16 +109,19 @@ expression: Literal l } + literal: | i=INT { LInt i } + identifier: | i=ID { Id i } + %inline located(X): x=X { Position.with_poss $startpos $endpos x }