12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061(* Copyright 2024 Yawar Amin
This file is part of dream-html.
dream-html is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.
dream-html 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 GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
dream-html. If not, see <https://www.gnu.org/licenses/>. *)openPpxlibopenAst_builder.Defaultletis_validpath=String.lengthpath>0&&path.[0]='/'letexpansion~locs=pexp_apply~loc(evar~loc"Dream_html.path")[Nolabel,estring~locs;Nolabel,estring~locs]leterr~locpath=Location.error_extensionf~loc"Invalid path: '%s'. Paths must start with a '/' character"pathletbinding_extender=Extension.V3.declare"path"Extension.Context.structure_itemAst_pattern.(pstr(pstr_valuedrop(value_binding~pat:__~expr:(estring__)^::nil)^::nil))(fun~ctxtpats->letloc=Expansion_context.Extension.extension_point_locctxtinifis_validsthenpstr_value~locNonrecursive[value_binding~loc~pat~expr:(expansion~locs)]elsepstr_extension~loc(err~locs)[])letexpr_extender=Extension.V3.declare"path"Extension.Context.expressionAst_pattern.(single_expr_payload(estring__))(fun~ctxts->letloc=Expansion_context.Extension.extension_point_locctxtinifis_validsthenexpansion~locselsepexp_extension~loc(err~locs))letpath_binding=Context_free.Rule.extensionbinding_extenderletpath_expr=Context_free.Rule.extensionexpr_extenderlet()=Driver.register_transformation~rules:[path_binding;path_expr]"dream-html.ppx"