This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlexer.mll
73 lines (66 loc) · 1.63 KB
/
lexer.mll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
open Lexing
open Parser
exception SyntaxError of (string)
let next_line lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <- {
pos with pos_bol = lexbuf.lex_curr_pos;
pos_lnum = pos.pos_lnum + 1
}
(*
| float { FLOAT (float_of_string (Lexing.lexeme lexbuf)) }
| white
*)
}
let white = [' ' '\t']+
let newline = '\n' | '\r' | "\r\n"
let int = '-'? ['0'-'9']* (*[^ 'a'-'z' 'A'-'Z']*)
let id = ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_']*
(* let invalidId = '-'? ['0'-'9']+(white) *)
(*
| "let" { LET }
| '=' { EQUALS }
*)
(* lexbuf available in rules *)
rule read =
parse
| white { read lexbuf }
| newline { next_line lexbuf; read lexbuf }
(* | ',' { COMMA } *)
| ';' { SEMICOLON }
| '{' { LEFT_BRACE }
| '}' { RIGHT_BRACE }
| '(' { LEFT_PARENS }
| ')' { RIGHT_PARENS }
| '*' { TIMES }
| '/' { DIVIDE }
| '-' { MINUS }
| '+' { PLUS }
| '=' { EQUALS }
| '>' { GREATER }
| '<' { LESSER }
| "<=" { LESSER_EQUAL}
| ">=" { GREATER_EQUAL }
(* | ":=" { ASSIGN } *)
| "!=" { NOT_EQUALS }
| int { INT (int_of_string (Lexing.lexeme lexbuf)) }
(* | fun { FUNCTION } *)
(* | match { MATCH } *)
(* | enum { TYPE_SUM } *)
(* | record { RECCORD_STRUCT } *)
| "if" { IF }
| "let" { LET }
| "in" { IN }
| "fn" { LAMBDA }
| "fun" { FUNCTION }
| "end" { END }
| "mod" { MODULO }
| "else" { ELSE }
| "when" { WHEN }
| "()" { UNIT }
| "True" { TRUE }
| "False" { FALSE }
| id { ID (Lexing.lexeme lexbuf) }
| eof { EOF }
| _ { raise (SyntaxError ("Unexepected character: " ^ Lexing.lexeme lexbuf)) }