12345678910111213141516171819202122232425262728293031323334353637383940414243444546openMigrate_parsetreeopenAst_404letstr?loc?attrss=Ast_helper.Exp.constant?loc?attrs(Pconst_string(s,None))letlocation_errorf~loc=Format.ksprintf(funerr->raise(Location.Error(Location.error~locerr)))letfind_file_path~locfile_name=letdirname=Location.absolute_pathloc.Location.loc_start.pos_fname|>Filename.dirnameinletabsolute_path=Filename.concatdirnamefile_nameinList.findSys.file_exists[absolute_path;file_name]letget_blob~locfile_name=tryletfile_path=find_file_path~locfile_nameinletc=open_in_binfile_pathinlets=String.init(in_channel_lengthc)(fun_->input_charc)inclose_inc;swith_->location_errorf~loc"[%%blob] could not find or load file %s"file_nameletmapper_config_cookies=letdefault_mapper=Ast_mapper.default_mapperin{default_mapperwithexpr=funmapperexpr->matchexprwith|{pexp_desc=Pexp_extension({txt="blob";loc},pstr)}->beginmatchpstrwith|PStr[{pstr_desc=Pstr_eval({pexp_loc=loc;pexp_desc=Pexp_constant(Pconst_string(file_name,_))},_)}]->str(get_blob~locfile_name)|_->location_errorf~loc"[%%blob] accepts a string, e.g. [%%blob \"file.dat\"]"end|other->default_mapper.exprmapperother}let()=Driver.register~name:"ppx_blob"Versions.ocaml_404mapper