more cases for commentary
This commit is contained in:
parent
f11c33ff18
commit
fadc63e30a
2 changed files with 71 additions and 64 deletions
|
@ -20,82 +20,88 @@ let hexa = "0x" ['0'-'9' 'a'-'f' 'A'-'F']
|
||||||
let bina = "0b" ['0'-'1']
|
let bina = "0b" ['0'-'1']
|
||||||
let octa = "0o" ['0'-'7']
|
let octa = "0o" ['0'-'7']
|
||||||
|
|
||||||
let integers = '-'? (digit+
|
let printable = [' ' '\t' '\n' '\r' (* 33-126 *)] (* pas sûr *)
|
||||||
| hexa+
|
|
||||||
| bina+
|
|
||||||
| octa+)
|
|
||||||
|
|
||||||
let printable = [' ' '\t' '\n' '\r' (*33-126*)] (*pas sûr*)
|
|
||||||
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,
|
(* On ne peut pas différencier au niveau du lexer var_id label_id et type_con,
|
||||||
* il faudra le faire à l'analyseur syntaxique *)
|
* il faudra le faire à l'analyseur syntaxique. On fait donc un "ident" pour
|
||||||
|
* identificateur *)
|
||||||
|
let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
|
||||||
|
|
||||||
let atom = '"'
|
let atom = '"'
|
||||||
let char = ['\'']atom['\'']
|
|
||||||
let string = ['\"']((atom | '\'' | "\\\""))['\"']
|
let constr_id = ['A'-'Z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
|
||||||
|
let type_variable = '`' ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
|
||||||
|
let int = '-'? (digit+ | hexa+ | bina+ | octa+)
|
||||||
|
let char = '\'' atom '\''
|
||||||
|
let string = '\"' ((atom | '\'' | "\\\"")) '\"'
|
||||||
|
|
||||||
(* let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?" *)
|
(* let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?" *)
|
||||||
|
|
||||||
|
|
||||||
rule token = parse
|
rule token = parse
|
||||||
(** Layout *)
|
(** Layout *)
|
||||||
| newline { next_line_and token lexbuf }
|
| newline { next_line_and token lexbuf }
|
||||||
| blank+ { token lexbuf }
|
| blank+ { token lexbuf }
|
||||||
| eof { EOF }
|
| eof { EOF }
|
||||||
| "{*" { commentary lexbuf; token lexbuf }
|
| "{*" { commentary lexbuf }
|
||||||
| "##" { commentary_line lexbuf }
|
| "##" { commentary_line lexbuf }
|
||||||
|
|
||||||
(** Keywords *)
|
(** Keywords *)
|
||||||
| "let" { LET }
|
| "let" { LET }
|
||||||
| "type" { TYPE }
|
| "type" { TYPE }
|
||||||
| "extern" { EXTERN }
|
| "extern" { EXTERN }
|
||||||
| "fun" { FUN }
|
| "fun" { FUN }
|
||||||
| "match" { MATCH }
|
| "match" { MATCH }
|
||||||
| "if" { IF }
|
| "if" { IF }
|
||||||
| "then" { THEN }
|
| "then" { THEN }
|
||||||
| "else" { ELSE }
|
| "else" { ELSE }
|
||||||
| "ref" { REF }
|
| "ref" { REF }
|
||||||
| "while" { WHILE }
|
| "while" { WHILE }
|
||||||
| "do" { DO }
|
| "do" { DO }
|
||||||
| "until" { UNTIL }
|
| "until" { UNTIL }
|
||||||
| "for" { FOR }
|
| "from" { FROM }
|
||||||
| "from" { FROM }
|
| "to" { TO }
|
||||||
| "to" { TO }
|
| "and" { AND }
|
||||||
| "and" { AND }
|
| "for" { FOR }
|
||||||
| "for" { FOR }
|
|
||||||
(* Fini ? *)
|
(* Fini ? *)
|
||||||
|
|
||||||
(** Binar operation : pas sûr pour celui là*)
|
(** Binar operation : pas sûr pour celui là *)
|
||||||
(* | binop as b { BINOP (* TODO *) } *)
|
(* | binop as b { BINOP b } *)
|
||||||
|
|
||||||
(** Operators *)
|
(** Operators *)
|
||||||
(* | '=' { EQUAL } *)
|
(* | '=' { EQUAL } *)
|
||||||
|
|
||||||
(* ponctuation *)
|
(** Ponctuation *)
|
||||||
| '(' { LPAREN }
|
| '(' { LPAREN }
|
||||||
| ')' { RPAREN }
|
| ')' { RPAREN }
|
||||||
| '[' { LBRACK }
|
| '[' { LBRACK }
|
||||||
| ']' { RBRACK }
|
| ']' { RBRACK }
|
||||||
| '_' { WILDCARD }
|
| '_' { WILDCARD }
|
||||||
| ':' { DPOINT }
|
| ':' { DPOINT }
|
||||||
| "->" { ARROW }
|
| "->" { ARROW }
|
||||||
| "<" { INFERIOR }
|
| "<" { INFERIOR }
|
||||||
| ">" { SUPERIOR }
|
| ">" { SUPERIOR }
|
||||||
|
|
||||||
(** Values *)
|
(** Values *)
|
||||||
| integers as i { INT (Mint.of_string i) }
|
| int as i { INT (Mint.of_string i) }
|
||||||
| ident as s { ID s }
|
| ident as s { ID s }
|
||||||
|
| type_variable as s { TID s }
|
||||||
|
|
||||||
(** Lexing error *)
|
(** Lexing error *)
|
||||||
| _ { error lexbuf "unexpected character." }
|
| _ { error lexbuf "unexpected character." }
|
||||||
|
|
||||||
and commentary = parse
|
(* TODO: Gérer les imbrications de commentaires *)
|
||||||
| "*}" { () }
|
and commentary = parse
|
||||||
| "{*" { commentary lexbuf; commentary lexbuf }
|
| "*}" { token lexbuf }
|
||||||
| _ { commentary lexbuf }
|
| newline { next_line_and commentary lexbuf }
|
||||||
|
|
||||||
and commentary_line = parse
|
(** Error *)
|
||||||
| '\n' { next_line_and token lexbuf }
|
| eof { error lexbuf "unclosed commentary." }
|
||||||
| _ { commentary_line lexbuf }
|
|
||||||
|
(** Commentary content *)
|
||||||
|
| _ { commentary lexbuf }
|
||||||
|
|
||||||
|
and commentary_line = parse
|
||||||
|
| newline { next_line_and token lexbuf }
|
||||||
|
| eof { EOF }
|
||||||
|
| _ { commentary_line lexbuf }
|
||||||
|
|
|
@ -48,7 +48,7 @@ fundef:
|
||||||
FunctionDefinition(p, e)
|
FunctionDefinition(p, e)
|
||||||
}
|
}
|
||||||
/* ts est temp */
|
/* ts est temp */
|
||||||
| DPOINT ts=located(type_scheme) i=located(identifier) p=pattern EQUAL e=located(expression) {
|
| DPOINT ts=located(type_scheme) i=located(identifier) p=located(pattern) EQUAL e=located(expression) {
|
||||||
FunctionDefinition(p, e)
|
FunctionDefinition(p, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,18 +63,19 @@ pattern:
|
||||||
|
|
||||||
|
|
||||||
ty:
|
ty:
|
||||||
| tc = type_constructor {
|
/* Temporaire None - compile pas */
|
||||||
|
/* | tc=type_constructor {
|
||||||
TyCon(tc, None)
|
TyCon(tc, None)
|
||||||
}
|
} */
|
||||||
|
|
||||||
(* Todo version avec l'optionnel*)
|
/* Todo version avec l'optionnel */
|
||||||
| ty1=located(ty) ARROW ty2=located(ty) {
|
| ty1=located(ty) ARROW ty2=located(ty) {
|
||||||
TyArrow(ty1, ty2)
|
TyArrow(ty1, ty2)
|
||||||
}
|
}
|
||||||
| ty1=located(ty) STAR ty2=located(ty) {
|
| ty1=located(ty) STAR ty2=located(ty) {
|
||||||
TyTuple([ty1; ty2])
|
TyTuple([ty1; ty2])
|
||||||
}
|
}
|
||||||
| ty1=located(ty) STAR ty2=located(ty) STAR liste_ty = separated_list(STAR,located(ty)) {
|
| ty1=located(ty) STAR ty2=located(ty) STAR liste_ty=separated_list(STAR, located(ty)) {
|
||||||
TyTuple(ty1::ty2::liste_ty)
|
TyTuple(ty1::ty2::liste_ty)
|
||||||
}
|
}
|
||||||
| LPAREN type_var=type_variable RPAREN {
|
| LPAREN type_var=type_variable RPAREN {
|
||||||
|
@ -83,8 +84,8 @@ ty:
|
||||||
|
|
||||||
|
|
||||||
type_scheme:
|
type_scheme:
|
||||||
(* il faut peut être modifié le séparateur*)
|
/* il faut peut être modifié le séparateur */
|
||||||
| LBRACK liste_typevar=separated_list(COMMA,located(type_variable)) RBRACK ty=located(ty) {
|
| LBRACK liste_typevar=separated_list(COMMA, located(type_variable)) RBRACK ty=located(ty) {
|
||||||
ForallTy(liste_typevar, ty)
|
ForallTy(liste_typevar, ty)
|
||||||
}
|
}
|
||||||
| ty=located(ty) {
|
| ty=located(ty) {
|
||||||
|
@ -99,7 +100,7 @@ type_variable:
|
||||||
|
|
||||||
|
|
||||||
type_constructor:
|
type_constructor:
|
||||||
| tcon = TID {
|
| tcon=TID {
|
||||||
TCon tcon
|
TCon tcon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue