Skip to content

Commit 2bd0759

Browse files
committed
[interpreter] Simplify lexer invocation
1 parent 908640a commit 2bd0759

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

interpreter/text/parse.ml

+7-16
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,19 @@ sig
99
val parse_channel : in_channel -> t
1010
end
1111

12-
let provider buf () =
13-
let tok = Lexer.token buf in
14-
let start = Lexing.lexeme_start_p buf in
15-
let stop = Lexing.lexeme_end_p buf in
16-
tok, start, stop
17-
18-
let convert_pos buf =
19-
{ Source.left = Lexer.convert_pos buf.Lexing.lex_start_p;
20-
Source.right = Lexer.convert_pos buf.Lexing.lex_curr_p
12+
let convert_pos lexbuf =
13+
{ Source.left = Lexer.convert_pos lexbuf.Lexing.lex_start_p;
14+
Source.right = Lexer.convert_pos lexbuf.Lexing.lex_curr_p
2115
}
2216

2317
let make (type a) (start : _ -> _ -> a) : (module S with type t = a) =
2418
(module struct
2519
type t = a
2620

27-
let parse name buf =
28-
Lexing.set_filename buf name;
29-
try
30-
MenhirLib.Convert.Simplified.traditional2revised start (provider buf)
31-
with
32-
| Parser.Error ->
33-
raise (Syntax (convert_pos buf, "unexpected token"))
21+
let parse name lexbuf =
22+
Lexing.set_filename lexbuf name;
23+
try start Lexer.token lexbuf with Parser.Error ->
24+
raise (Syntax (convert_pos lexbuf, "unexpected token"))
3425

3526
let parse_string s =
3627
parse "string" (Lexing.from_string ~with_positions:true s)

0 commit comments

Comments
 (0)