This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.mll
105 lines (100 loc) · 2.77 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
open Parser
let next_line = Lexing.new_line
}
let int = '-'? ['0'-'9']+
let float = '-'?['0'-'9']+ '.' ['0' - '9']*
let white = [' ' '\t']+
let newline = '\n'
let id_rest = ['a'-'z' 'A'-'Z' '0'-'9' '_']
let id = ('_' id_rest+ | ['a' - 'z' 'A'-'Z'] id_rest*)
let non_comment = [^ '/' '*' '\n']+
let comment_delim = [ '/' '*' ]
let operators = ['+' '-' '*' '/' '%' '<' '>' '=' '!' '&' '^' '|' '#' '@']+
let not_newline = [^'\n']+
let nonquote = [^'"']+
rule read =
parse
| "##pos" { let (nm,pos) = pd1 lexbuf in
Locations.set_file_name lexbuf nm pos;
read lexbuf }
| "//" { line_comment lexbuf; read lexbuf }
| "/*" { comment lexbuf; read lexbuf }
| "/**" { comment lexbuf; read lexbuf }
| white { read lexbuf }
| newline { next_line lexbuf; read lexbuf }
| "()" { UNIT }
| int { let i = int_of_string @@ Lexing.lexeme lexbuf in LabelManager._internal_incr i; INT i }
| "ifnull" { IFNULL }
| "if" { IF }
| "then" { THEN }
| "else" { ELSE }
| "let" { LET }
| "in" { IN }
| "length" { LENGTH }
| '*' { STAR }
| ';' { SEMI }
| ':' { COLON }
| ',' { COMMA }
| '[' { LBRACKET }
| ']' { RBRACKET }
| "<-" { LARROW }
| "mkref" { MKREF }
| "mkarray" { MKARRAY }
| "alias" { ALIAS }
| "assert" { ASSERT }
| "true" { TRUE }
| "false" { FALSE }
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
| '}' { RBRACE }
| "/\\" { AND }
| '.' { DOT }
| '=' { EQ }
| 'T' { TOP }
| "->" { ARROW }
| '~' { NU }
| '$' { DOLLAR }
| ":=" { ASSIGN }
| "null" { NULL }
| operators { OPERATOR (Lexing.lexeme lexbuf) }
| '_' { UNDERSCORE }
| id { ID (Lexing.lexeme lexbuf) }
| eof { EOF }
| _ { failwith @@ "Invalid token " ^ (Lexing.lexeme lexbuf) }
and comment =
parse
| newline { next_line lexbuf; comment lexbuf }
| non_comment { comment lexbuf }
| "*/" { () }
| "/*" { comment lexbuf; comment lexbuf }
| "/**" { comment lexbuf; comment lexbuf }
| comment_delim { comment lexbuf }
and line_comment =
parse
| not_newline { line_comment lexbuf }
| newline { next_line lexbuf }
and pd1 =
parse
| white { pd1 lexbuf }
| '"' { str_content lexbuf }
| _ { failwith @@ "Invalid token " ^ (Lexing.lexeme lexbuf) }
and str_content =
parse
| nonquote { end_str (Lexing.lexeme lexbuf) lexbuf }
| _ { failwith @@ "Invalid token " ^ (Lexing.lexeme lexbuf) }
and end_str nm =
parse
| '"' { pd2 nm lexbuf }
| _ { failwith @@ "Invalid token " ^ (Lexing.lexeme lexbuf) }
and pd2 nm =
parse
| white { pd2 nm lexbuf }
| int { let v = int_of_string @@ Lexing.lexeme lexbuf in pd3 (nm,v) lexbuf }
| _ { failwith @@ "Invalid token " ^ (Lexing.lexeme lexbuf) }
and pd3 g =
parse
| white { pd3 g lexbuf }
| newline { next_line lexbuf; g }
| _ { failwith @@ "Invalid token " ^ (Lexing.lexeme lexbuf) }