| 123456789101112131415161718192021222324252627 |
- open Lexing
- open Ast
- let get_loc lexbuf =
- Util.loc_from_lexpos lexbuf.lex_curr_p lexbuf.lex_curr_p
- let shift_loc (fname, ystart, yend, xstart, xend) yshift xshift =
- (fname, ystart + yshift, yend + yshift, xstart + xshift, xend + xshift)
- let parse_with_error lexbuf =
- try Some (Parser.program Lexer.token lexbuf) with
- | Lexer.SyntaxError msg ->
- raise (LocError (shift_loc (get_loc lexbuf) 0 (-1), msg))
- | Parser.Error ->
- raise (LocError (get_loc lexbuf, "syntax error"))
- let phase input =
- prerr_endline "- Parse input";
- match input with
- | FileContent (display_name, content, args) ->
- let lexbuf = Lexing.from_string content in
- lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = display_name };
- let ast = parse_with_error lexbuf in
- (match ast with
- | None -> raise (CompileError "no syntax tree was constructed")
- | Some node -> Ast (node, args))
- | _ -> raise (InvalidInput "parse")
|