12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879(*
* Copyright (c) 2019-2020 Craig Ferguson <me@craigfe.io>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openPpxlibmoduleMake(T:sigvalnamespace:stringvaldefault_library:stringend)=structmoduleAttributes=Attributes.Make(T)letwith_enginef~loc~path:_=let(moduleS)=Ast_builder.makelocinf(moduleEngine.Located(Attributes)(S):Engine.S)letargs()=letopenDeriving.ArgsinMeta_deriving.Args.[arg"name"(estring__);arg"lib"__]letlibrary=lazy(letlibrary=ref(SomeT.default_library)inletdoc=Format.sprintf"<module-path> Set the module path containing the combinators to \
use (defaults to %s). An empty string is interpreted as the \
current module."T.default_libraryinPpxlib.Driver.add_arg"--lib"(Arg.String(function""->library:=None|s->library:=Somes))~doc;library)letregister_deriver?plugins:(supported_plugins=Meta_deriving.Plugin.defaults)()=letlibrary=Lazy.forcelibraryinletstr_type_decl=letattributes=Attributes.allinMeta_deriving.make_generator~attributes~supported_plugins~args:(args())(with_engine@@fun(moduleL)pluginsinput_astnamelib->letlib=Option.foldlib~some:L.parse_lib~none:!libraryinL.derive_str~plugins~name~libinput_ast)inletsig_type_decl=Meta_deriving.make_generator~supported_plugins~args:(args())(with_engine@@fun(moduleL)pluginsinput_astnamelib->letlib=Option.foldlib~some:L.parse_lib~none:!libraryinL.derive_sig~plugins~name~libinput_ast)inDeriving.add~str_type_decl~sig_type_declT.namespace|>Deriving.ignoreletregister_extension?no_reserve_namespace()=letlibrary=Lazy.forcelibraryinletextension=Extension.declare(T.namespace^".typ")Extension.Context.expressionAst_pattern.(ptyp__)(with_engine@@fun(moduleL)->L.expand_typ?lib:!library)in(matchno_reserve_namespacewith|Some()->()|None->Reserved_namespaces.reserveT.namespace);Driver.register_transformation~extensions:[extension]T.namespaceend