aboutsummaryrefslogblamecommitdiffstats
path: root/lib/front.ml
blob: 7cacc20a560bdb17da55cc4033b010e04903ccf4 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                            
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))