123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899(* Yoann Padioleau
*
* Copyright (C) 2019 Yoann Padioleau
*
* 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_skipmodulePI=Parse_info(*****************************************************************************)(* Prelude *)(*****************************************************************************)(* Lots of copy paste with my other parsers (e.g. C++, PHP, sql) but
* copy paste is sometimes ok.
*)(*****************************************************************************)(* Types *)(*****************************************************************************)typeprogram_and_tokens=Ast_skip.programoption*Parser_skip.tokenlist(*****************************************************************************)(* Error diagnostic *)(*****************************************************************************)leterror_msg_toktok=Parse_info.error_message_info(TH.info_of_toktok)(*****************************************************************************)(* Lexing only *)(*****************************************************************************)lettokens2file=lettoken=Lexer_skip.tokeninParse_info.tokenize_all_and_adjust_posfiletokenTH.visitor_info_of_tokTH.is_eoflettokensa=Common.profile_code"Parse_skip.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_skip.main"(fun()->Parser_skip.mainlexerlexbuf_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=PI.line_of_info(TH.info_of_tokcur)inParse_info.print_badline_error(0,checkpoint2)filelines;end;stat.PI.bad<-Common.catfilename|>List.length;(None,toks),statletparsea=Common.profile_code"Parse_skip.parse"(fun()->parse2a)letparse_programfile=let((astopt,_toks),_stat)=parsefileinCommon2.someastopt