123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107openCommonmoduleFlag=Flag_parsing(*****************************************************************************)(* Subsystem testing *)(*****************************************************************************)lettest_tokens_mlfile=ifnot(file=~".*\\.ml[iyl]?")thenpr2"warning: seems not a ocaml file";Flag.verbose_lexing:=true;Flag.verbose_parsing:=true;Flag.exn_when_lexical_error:=true;lettoks=Parse_ml.tokensfileintoks|>List.iter(funx->pr2_genx);()lettest_parse_ml_or_mlixs=letxs=List.mapCommon.fullpathxsinletfullxs=Lib_parsing_ml.find_source_files_of_dir_or_filesxs|>Skip_code.filter_files_if_skip_listinletstat_list=ref[]infullxs|>Console.progress(funk->List.iter(funfile->k();let(_xs,stat)=Common.save_excursionFlag.error_recoverytrue(fun()->Parse_ml.parsefile)inCommon.pushstatstat_list;));Parse_info.print_parsing_stat_list!stat_list;()lettest_dump_mlfile=letast=Parse_ml.parse_programfileinletv=Meta_cst_ml.vof_any(Cst_ml.Programast)inlets=Ocaml.string_of_vvinprs(*****************************************************************************)(* One shot *)(*****************************************************************************)letrefactor_grammarsubst_filefile=leth=Hashtbl.create101inletxs=Common.catsubst_fileinletrecpopulate_hashxs=matchxswith|[]->()|[x]->failwith("pb not a pair number: "^x)|x::y::xs->(ifx=~"\\([A-Za-z]+\\)"thenlettarget=Common.matched1xinify=~" \\([A-Za-z]+\\)"thenletorig=Common.matched1yinHashtbl.addhorigtargetelsefailwith("wrong format: "^x^y)elsefailwith("wrong format: "^x^y));populate_hashxsinpopulate_hashxs;letys=Common.catfileinys|>List.iter(funl->lets=Common2.global_replace_regexp"\\([a-zA-Z_][A-Za-z_0-9]*\\)"(funs->tryHashtbl.findhswithNot_found->s)linprs);()(*****************************************************************************)(* Main entry for Arg *)(*****************************************************************************)letactions()=["-tokens_ml"," <file>",Common.mk_action_1_argtest_tokens_ml;"-parse_ml"," <files or dirs>",Common.mk_action_n_argtest_parse_ml_or_mli;"-dump_ml"," <file>",Common.mk_action_1_argtest_dump_ml;"-refactor_grammar"," <subst_file> <file>",Common.mk_action_2_argrefactor_grammar;]