123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154(**************************************************************************)(* *)(* Alt-Ergo: The SMT Solver For Software Verification *)(* Copyright (C) 2013-2023 --- OCamlPro SAS *)(* *)(* This file is distributed under the terms of OCamlPro *)(* Non-Commercial Purpose License, version 1. *)(* *)(* As an exception, Alt-Ergo Club members at the Gold level can *)(* use this file under the terms of the Apache Software License *)(* version 2.0. *)(* *)(* --------------------------------------------------------------- *)(* *)(* The Alt-Ergo theorem prover *)(* *)(* Sylvain Conchon, Evelyne Contejean, Francois Bobot *)(* Mohamed Iguernelala, Stephane Lescuyer, Alain Mebsout *)(* *)(* CNRS - INRIA - Universite Paris Sud *)(* *)(* Until 2013, some parts of this code were released under *)(* the Apache Software License version 2.0. *)(* *)(* --------------------------------------------------------------- *)(* *)(* More details can be found in the directory licenses/ *)(* *)(**************************************************************************)openAltErgoLibopenOptionsopenErrorsmoduletypePARSER_INTERFACE=sigvalfile:Lexing.lexbuf->Parsed.filevalexpr:Lexing.lexbuf->Parsed.lexprvaltrigger:Lexing.lexbuf->Parsed.lexprlist*boolendletparsers=ref([]:(string*(modulePARSER_INTERFACE))list)letregister_parser~langnew_parser=ifList.mem_assoclang!parsersthenbeginPrinter.print_wrn"A parser for extension %S is already registered. \
It will be hidden !"lang;end;parsers:=(lang,new_parser)::!parsersletfind_parserext_optformat=tryList.assocext_opt!parserswithNot_found->ifString.equalext_opt".why"thenbeginPrinter.print_wrn"please use the AB-Why3 plugin for file in Why3 format. \
.why and .mlw extensions are depreciated and used for Why3 files. \
Continue with native Alt-Ergo parsers!";tryList.assoc".ae"!parserswithNot_found->error(Parser_error("Error: no parser registered for the provided \
input format %S ?@."^format))endelseerror(Parser_error("Error: no parser registered for the provided \
input format %S ?@."^format))letset_output_formatfmt=ifOptions.get_infer_output_format()thenmatchfmtwith|Options.Unknowns->Printer.print_wrn"The output format %s is not supported"s|fmt->Options.set_output_formatfmtletget_input_parserfmt=set_output_formatfmt;matchfmtwith|Options.Native->find_parser".ae""native"|Options.Smtlib2->find_parser".smt2""smtlib2"|Options.Why3->find_parser".why""why3"|Options.Unknowns->find_parserssletget_parserext_opt=ifOptions.get_infer_input_format()thenmatchext_optwith|Someext->get_input_parser(Options.match_extensionext)|None->error(Parser_error"Error: no extension found, can't infer input format@.")elseget_input_parser(Options.get_input_format())letparse_file?langlexbuf=letmoduleParser=(valget_parserlang:PARSER_INTERFACE)inParser.filelexbufletparse_expr?langlexbuf=letmoduleParser=(valget_parserlang:PARSER_INTERFACE)inParser.exprlexbufletparse_trigger?langlexbuf=letmoduleParser=(valget_parserlang:PARSER_INTERFACE)inParser.triggerlexbufletparse_input_filefile=ifget_verbose()thenPrinter.print_dbg~module_name:"Parsers"~function_name:"parse_input_file""parsing file \"%s\""file;letcin,lb,opened_cin,ext=ifFilename.check_suffixfile".zip"thenletext=Filename.extension(Filename.chop_extensionfile)inletfile_content=My_zip.extract_zip_filefileinstdin,Lexing.from_stringfile_content,false,extelseletext=Filename.extensionfileinifnot(String.equalfile"")thenletcin=open_infileincin,Lexing.from_channelcin,true,extelsestdin,Lexing.from_channelstdin,false,extintryletext=ifString.equalext""thenNoneelseSomeextinleta=parse_file?lang:extlbinifopened_cinthenclose_incin;awith|Errors.Errore->ifopened_cinthenclose_incin;raise(Errore)|Parsing.Parse_errorase->ifopened_cinthenclose_incin;raiseeletparse_problem~filename~preludes=letacc=parse_input_filefilenameinList.fold_left(funaccprelude->List.rev_append(List.rev(parse_input_fileprelude))acc)acc(List.revpreludes)letparse_problem_as_string~content~format=tryletlb=Lexing.from_stringcontentinparse_file?lang:formatlbwith|Errors.Errore->Format.printf"%a"Errors.reporte;raise(Errore)|Parsing.Parse_errorase->raisee