| 1234567891011121314151617181920212223 |
- open Lexing
- open Types
- let loc_from_lexpos pstart pend =
- let (fname, ystart, xstart) = begin
- pstart.pos_fname,
- pstart.pos_lnum,
- (pstart.pos_cnum - pstart.pos_bol + 1)
- end in
- (fname, ystart, xstart)
- let loc_msg lexbuf msg =
- let p = lexbuf.lex_curr_p in
- let y = p.pos_lnum in
- let x = p.pos_cnum - p.pos_bol in
- Printf.sprintf "%s at line %d, character %d" msg y x
- let parse_with_error lexbuf =
- try Parser.program Lexer.token lexbuf with
- | Lexer.Syntax_error msg ->
- raise (Fatal_error (loc_msg lexbuf msg))
- | Parser.Error ->
- raise (Fatal_error (loc_msg lexbuf "syntax error"))
|