You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
851 B

module Make (M : S.S) = struct
let fail s = Utils.failwith (Format.sprintf "parser: %s" s)
let from_lexing buf =
let exception Stop in
try M.Parser.file M.Lexer.token buf
with M.Parser.Error ->
let err_pos = Lexing.lexeme_start buf in
let err_line, line_offset = (ref 1, ref 0) in
( try
List.iter
(fun x ->
if x > err_pos then raise Stop ;
incr err_line ;
line_offset := x)
(M.Lexer.Helper.get_mem_new_line ())
with Stop -> () ) ;
let offset = err_pos - !line_offset in
fail
(Format.sprintf "on line %d at offset %d, syntax error" !err_line
offset)
let from_file f =
let chan = open_in f in
let buf = Lexing.from_channel chan in
let res = from_lexing buf in
close_in chan ; res
end