-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_utils.ml
132 lines (109 loc) · 3.36 KB
/
parser_utils.ml
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
let parser_error_handle parser next_token =
try parser next_token
with Parser.Error ->
let current_start = Lexer.get_current_start ()
and current_end = Lexer.get_current_end ()
and current_token = Lexer.get_current_token () in
Error.raise_error Error.parsing
current_start current_end
(Printf.sprintf "Unexpected token: '%s'."
(Lexer.string_of_token current_token))
let convert_parser parser =
MenhirLib.Convert.Simplified.traditional2revised
parser
let typ_expr_parser = convert_parser Parser.typ_expr
let kind_expr_parser = convert_parser Parser.kind_expr
let term_expr_parser = convert_parser Parser.main_term_expr
let prog_parser = convert_parser Parser.prog
module String = struct
module Raw = struct
module Typ = struct
let parse s =
let lexbuf = Ulexing.from_utf8_string s in
let file = "<string>" in
parser_error_handle
typ_expr_parser (fun () -> Lexer.token file lexbuf)
end
module Kind = struct
let parse s =
let lexbuf = Ulexing.from_utf8_string s in
let file = "<string>" in
parser_error_handle
kind_expr_parser (fun () -> Lexer.token file lexbuf)
end
module Term = struct
let parse s =
let lexbuf = Ulexing.from_utf8_string s in
let file = "<string>" in
parser_error_handle
term_expr_parser (fun () -> Lexer.token file lexbuf)
end
module Prog = struct
let parse s =
let lexbuf = Ulexing.from_utf8_string s in
let file = "<string>" in
parser_error_handle
prog_parser (fun () -> Lexer.token file lexbuf)
end
end
module Typ = struct
let parse s =
Ast_utils.Encode.Typ.typ (Raw.Typ.parse s)
end
module Kind = struct
let parse s =
Ast_utils.Encode.Typ.kind (Raw.Kind.parse s)
end
module Term = struct
let parse s =
Ast_utils.Encode.Term.term (Raw.Term.parse s)
end
module Prog = struct
let parse s =
Ast_utils.Encode.Prog.prog (Raw.Prog.parse s)
end
end
module Channel = struct
module Raw = struct
module Typ = struct
let parse chan file =
let lexbuf = Ulexing.from_utf8_channel chan in
parser_error_handle
typ_expr_parser (fun () -> Lexer.token file lexbuf)
end
module Kind = struct
let parse chan file =
let lexbuf = Ulexing.from_utf8_channel chan in
parser_error_handle
kind_expr_parser (fun () -> Lexer.token file lexbuf)
end
module Term = struct
let parse chan file =
let lexbuf = Ulexing.from_utf8_channel chan in
parser_error_handle
term_expr_parser (fun () -> Lexer.token file lexbuf)
end
module Prog = struct
let parse chan file =
let lexbuf = Ulexing.from_utf8_channel chan in
parser_error_handle
prog_parser (fun () -> Lexer.token file lexbuf)
end
end
module Typ = struct
let parse chan file =
Ast_utils.Encode.Typ.typ (Raw.Typ.parse chan file)
end
module Kind = struct
let parse chan file =
Ast_utils.Encode.Typ.kind (Raw.Kind.parse chan file)
end
module Term = struct
let parse chan file =
Ast_utils.Encode.Term.term (Raw.Term.parse chan file)
end
module Prog = struct
let parse chan file =
Ast_utils.Encode.Prog.prog (Raw.Prog.parse chan file)
end
end