blob: 7cacc20a560bdb17da55cc4033b010e04903ccf4 (
plain) (
tree)
|
|
let parse_string source =
let lexbuf = Lexing.from_string source in
match Parser.program Lexer.token lexbuf with
| statements -> Ok statements
| exception Lexer.Error message ->
let position = lexbuf.Lexing.lex_curr_p in
Error
(Printf.sprintf "lexical error at line %d: %s"
position.Lexing.pos_lnum message)
| exception Parser.Error ->
let position = lexbuf.Lexing.lex_curr_p in
Error
(Printf.sprintf "syntax error at line %d, before %S"
position.Lexing.pos_lnum (Lexing.lexeme lexbuf))
|