1 (* Simple wrapper tying together parser and lexer *)
3 module type Parser_type
=
7 val input
: (Lexing.lexbuf
-> token
) -> Lexing.lexbuf
-> result
8 val rule
: Lexing.lexbuf
-> token
11 exception Error
of exn
* (int * int * string)
13 module Make
(T
: Parser_type
) =
15 let parse_buf_exn lexbuf
=
20 let curr = lexbuf
.Lexing.lex_curr_p
in
21 let line = curr.Lexing.pos_lnum
in
22 let cnum = curr.Lexing.pos_cnum
- curr.Lexing.pos_bol
in
23 let tok = Lexing.lexeme lexbuf
in
24 raise
(Error
(exn
,(line,cnum,tok)))
27 let parse_buf lexbuf
= try Some
(parse_buf_exn lexbuf
) with exn
-> None
29 let parse_stdin () = parse_buf (Lexing.from_channel stdin
)
30 let parse_string str
= (*Error.log "Parsing : %s" str; *)
31 parse_buf (Lexing.from_string str
)
33 let parse_file filename
=
34 let contents = try Std.input_file filename
with exn
-> "" in