123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475(* Yoann Padioleau
*
* Copyright (C) 2019 r2c
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library 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.
*)openCommon(*****************************************************************************)(* Prelude *)(*****************************************************************************)(* Wrappers around many languages to transform them in a generic AST
* (see ast_generic.ml)
*)(*****************************************************************************)(* Entry point *)(*****************************************************************************)letparse_with_langlangfile=matchlangwith|Lang.Python->letast=Parse_python.parse_programfileinResolve_python.resolveast;Python_to_generic.programast|Lang.Javascript->letcst=Parse_js.parse_programfileinletast=Ast_js_build.programcstinJs_to_generic.programast|Lang.C->(* this internally uses the CST for c++ *)letast=Parse_c.parse_programfileinC_to_generic.programast|Lang.Java->letast=Parse_java.parse_programfileinJava_to_generic.programast|Lang.ML->letcst=Parse_ml.parse_programfileinletast=Ast_ml_build.programcstinlet_=Ml_to_generic.programastinraiseTodoletparse_programfile=matchLang.lang_of_filename_optfilewith|Somex->parse_with_langxfile|None->failwith(spf"unsupported file for AST generic: %s"file)letparse_patternlangstr=Common.save_excursionFlag_parsing.sgrep_modetrue(fun()->matchlangwith|Lang.Python->letany=Parse_python.any_of_stringstrinPython_to_generic.anyany|Lang.Javascript->letany_cst=Parse_js.any_of_stringstrinletany=Ast_js_build.anyany_cstinJs_to_generic.anyany|Lang.C->letany=Parse_c.any_of_stringstrinC_to_generic.anyany|Lang.Java->letany=Parse_java.any_of_stringstrinJava_to_generic.anyany|Lang.ML->raiseTodo)