12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(* Yoann Padioleau
*
* Copyright (C) 2010 Facebook
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL)
* version 2 as published by the Free Software Foundation.
*
* 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
* file license.txt for more details.
*)openCommonmoduleFlag=Flag_parsingmoduleTH=Token_helpers_mlmodulePI=Parse_info(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*****************************************************************************)(* Types *)(*****************************************************************************)typeprogram_and_tokens=Cst_ml.programoption*Parser_ml.tokenlist(*****************************************************************************)(* Error diagnostic *)(*****************************************************************************)leterror_msg_toktok=Parse_info.error_message_info(TH.info_of_toktok)(*****************************************************************************)(* Lexing only *)(*****************************************************************************)lettokens2file=lettoken=Lexer_ml.tokeninParse_info.tokenize_all_and_adjust_posfiletokenTH.visitor_info_of_tokTH.is_eoflettokensa=Common.profile_code"Parse_ml.tokens"(fun()->tokens2a)(*****************************************************************************)(* Main entry point *)(*****************************************************************************)letparse2filename=letstat=Parse_info.default_statfilenameinlettoks=tokensfilenameinlettr,lexer,lexbuf_fake=Parse_info.mk_lexer_for_yacctoksTH.is_commentintry(* -------------------------------------------------- *)(* Call parser *)(* -------------------------------------------------- *)letxs=Common.profile_code"Parser_ml.main"(fun()->iffilename=~".*\\.mli"thenParser_ml.interfacelexerlexbuf_fakeelseParser_ml.implementationlexerlexbuf_fake)instat.PI.correct<-(Common.catfilename|>List.length);(Somexs,toks),statwithParsing.Parse_error->letcur=tr.PI.currentinifnot!Flag.error_recoverythenraise(PI.Parsing_error(TH.info_of_tokcur));if!Flag.show_parsing_errorthenbeginpr2("parse error \n = "^error_msg_tokcur);letfilelines=Common2.cat_arrayfilenameinletcheckpoint2=Common.catfilename|>List.lengthinletline_error=TH.line_of_tokcurinParse_info.print_badline_error(0,checkpoint2)filelines;end;stat.PI.bad<-Common.catfilename|>List.length;(None,toks),statletparsea=Common.profile_code"Parse_ml.parse"(fun()->parse2a)letparse_programfile=let((astopt,_toks),_stat)=parsefileinCommon2.someastopt