1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(*
* 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)letderiving_args()=Deriving.Args.(empty+>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()=letlibrary=Lazy.forcelibraryinletstr_type_decl=letattributes=Attributes.allinDeriving.Generator.make~attributes(deriving_args())(with_engine@@fun(moduleL)input_astnamelib->letlib=matchlibwithSomes->L.parse_libs|None->!libraryinL.derive_str?name?libinput_ast)inletsig_type_decl=Deriving.Generator.make(deriving_args())(with_engine@@fun(moduleL)input_astnamelib->letlib=matchlibwithSomes->L.parse_libs|None->!libraryinL.derive_sig?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