This repository has been archived on 2024-01-18. You can view files and clone it, but cannot push or open issues or pull requests.
compilation/flap/src/hopix/hopixLexer.mll
2023-10-11 20:16:46 +02:00

91 lines
2.7 KiB
OCaml

{ (* -*- tuareg -*- *)
open Lexing
open Error
open Position
open HopixParser
let next_line_and f lexbuf =
Lexing.new_line lexbuf;
f lexbuf
let error lexbuf =
error "during lexing" (lex_join lexbuf.lex_start_p lexbuf.lex_curr_p)
}
let newline = ('\010' | '\013' | "\013\010")
let blank = [' ' '\009' '\012']
let digit = ['0'-'9']
let hexa = "0x" ['0'-'9' 'a'-'f' 'A'-'F']
let bina = "0b" ['0'-'1']
let octa = "0o" ['0'-'7']
let integers = '-'? (digit+
| hexa+
| bina+
| octa+)
let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
let constr_id = ['A'-'Z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
let type_variable = '\''ident
(*TODO type_con*)
let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?"
rule token = parse
(** Layout *)
| newline { next_line_and token lexbuf }
| blank+ { token lexbuf }
| eof { EOF }
| "{*" { commentary lexbuf; token 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 }
(* Fini ? *)
(* binar operation : pas sûr pour celui là*)
| binop as b { BINOP (* TODO *) }
(** Operators *)
| '=' { EQUAL }
(* ponctuation *)
| '(' { LPAREN }
| ')' { RPAREN }
| '[' { LBRACK }
| ']' { RBRACK }
| '_' { WILDCARD }
(** Values *)
| integers as i { INT (Mint.of_string i) }
| ident as s { ID s }
(** Lexing error *)
| _ { error lexbuf "unexpected character." }
and commentary = parse
| "*}" { () }
| "{*" { commentary lexbuf; commentary lexbuf }
| _ { commentary lexbuf }
and commentary_line = parse
| '\n' { next_line_and token lexbuf }
| _ { commentary_line lexbuf }