-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlexzen.mll
89 lines (78 loc) · 2.46 KB
/
lexzen.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
(* Copyright 2005 INRIA *)
{
Version.add "$Id: lexzen.mll,v 1.13 2012-04-11 18:27:26 doligez Exp $";;
open Lexing;;
open Parsezen;;
open Printf;;
}
let newline = ('\010' | '\013' | "\013\010")
let space = [' ' '\009' '\012']
let idstart = ['A'-'Z' 'a'-'z' '_' '0'-'9']
let idchar = ['A'-'Z' 'a'-'z' '0'-'9' '_' '\'' '.']
let stringchar = [^ '\000'-'\031' '\"' '\\' '\127'-'\255']
let hexdigit = ['0'-'9' 'A'-'F' 'a'-'f']
let stringescape = '\\' (['a' 'b' 'f' 'n' 'r' 't' 'v' '\'' '\"' '\\' '?'] |
('x' hexdigit hexdigit))
rule token = parse
| '#' [^ '\010' '\013'] * { token lexbuf }
| ';' [^ '\010' '\013'] * { token lexbuf }
| newline {
lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with
pos_bol = lexbuf.lex_curr_p.pos_cnum;
pos_lnum = lexbuf.lex_curr_p.pos_lnum + 1;
};
token lexbuf
}
| space + { token lexbuf }
| "(" { OPEN }
| ")" { CLOSE }
| '$' ['0' - '9'] + {
let s = Lexing.lexeme lexbuf in
let i = int_of_string (String.sub s 1 (String.length s - 1)) in
INT i
}
| "$def" { DEF }
| "$fix" { FIX }
| "$fixpoint" { FIXPOINT }
| "$goal" { GOAL }
| "$hyp" { HYP }
| "$include" { INCLUDE }
| "$indset" { INDSET }
| "$indprop" { INDPROP }
| "$let" { LET }
| "$match" { MATCH }
| "$self" { SELF }
| "$sig" { SIG }
| "-." { NOT }
| "/\\" { AND }
| "\\/" { OR }
| "=>" { IMPLY }
| "<=" { RIMPLY }
| "<=>" { EQUIV }
| "T." { TRUE }
| "F." { FALSE }
| "A." { ALL }
| "E." { EX }
| "t." { TAU }
| "=" { EQUAL }
| "\"" (stringchar | stringescape)* "\"" {
let s = Lexing.lexeme lexbuf in
STRING (String.sub s 1 (String.length s - 2))
}
| "\"" (stringchar | stringescape)* "\\" stringchar {
let s = Lexing.lexeme lexbuf in
let msg = sprintf "bad escape in string: \\%c" s.[String.length s - 1] in
raise (Error.Lex_error msg)
}
| "\"" (stringchar | stringescape)* "\\"? _ {
let s = Lexing.lexeme lexbuf in
let c = String.escaped (String.sub s (String.length s - 1) 1) in
let msg = sprintf "bad character in string: %s" c in
raise (Error.Lex_error msg)
}
| idstart idchar* { IDENT (Lexing.lexeme lexbuf) }
| eof { EOF }
| _ {
let msg = sprintf "bad character %C" (Lexing.lexeme_char lexbuf 0) in
raise (Error.Lex_error msg)
}