summaryrefslogtreecommitdiff
path: root/frontend/file_parser.ml
blob: 85eb9cd2a80c043baccfeb2123375a409dea91e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
open Ast
open Ast_printer
open Lexing

let parse_file (filename : string) : prog =
  let f = open_in filename in
  let lex = from_channel f in
  try
    lex.lex_curr_p <- { lex.lex_curr_p with pos_fname = filename; };
    Parser.file Lexer.token lex
  with
  | Parser.Error ->
    Util.error (Printf.sprintf "Parse error (invalid syntax) near %s"
                  (string_of_position lex.lex_start_p))
  | Failure "lexing: empty token" ->
    Util.error (Printf.sprintf "Parse error (invalid token) near %s"
                  (string_of_position lex.lex_start_p))