(* Goalfile parser * Copyright (C) 2019 Richard W.M. Jones * Copyright (C) 2019 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) open Lexer open Lexing open Printf let parse lexbuf = let print_position fp lexbuf = let pos = lexbuf.lex_curr_p in fprintf fp "%s:%d:%d" pos.pos_fname pos.pos_lnum (pos.pos_cnum - pos.pos_bol) in try Parser.file Lexer.read lexbuf with | SyntaxError msg -> eprintf "%a: %s\n" print_position lexbuf msg; exit 1 | Parser.Error -> eprintf "%a: parse error\n" print_position lexbuf; exit 1 let parse_from_file filename = let fp = open_in filename in let lexbuf = Lexing.from_channel fp in lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename }; let file : Ast.file = parse lexbuf in close_in fp; file