123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2019 The MOPSA Project. *)(* *)(* This program is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as published *)(* by the Free Software Foundation, either version 3 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 Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(**
Opens and parses a file given as argument.
*)openMopsa_utilsopenU_astopenU_ast_printeropenLexing(* parsing, with nice error messages *)letparse_from_strings=letlex=from_stringsintrylex.lex_curr_p<-{lex.lex_curr_pwithpos_cnum=0};U_parser.fileU_lexer.tokenlexwith|Failures->letrange=Location.from_lexing_range(Lexing.lexeme_start_plex)(Lexing.lexeme_end_plex)inExceptions.syntax_errorrange"%s"sletparse_file(filename:string):prog=letf=open_infilenameinletlex=from_channelfintrylex.lex_curr_p<-{lex.lex_curr_pwithpos_fname=filename;};U_parser.fileU_lexer.tokenlexwith|U_parser.Error->letrange=Location.from_lexing_range(Lexing.lexeme_start_plex)(Lexing.lexeme_end_plex)inExceptions.unnamed_syntax_errorrange|Failurex->ifx="lexing: empty token"then(letrange=Location.from_lexing_range(Lexing.lexeme_start_plex)(Lexing.lexeme_end_plex)inExceptions.unnamed_syntax_errorrange)elseraise(Exceptions.panic"%s"x)