123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384(*********************************************************************************)(* OCaml-CSS *)(* *)(* Copyright (C) 2023 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* This program 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, version 3 of the License. *)(* *)(* This program 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 this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)moduleLog=LogmoduleT=TmoduleU=UmoduleVp=VpmoduleS=SmoduleSp=SpmoduleP=P(* module Sh = Sh *)moduleC=CmoduleKw=Kw(** A CSS structure is a list of {!S.statement}s. *)type'nscss='nsS.statementlist(** [parse_string string] parses the given [string], creating the
required {!T.type-ctx} to compute locations.
Optional argument [fname] can be used to specify a filename
in the [fname] field of {!T.pos} structures.
Raises {!T.Error} in case of error.
*)letparse_string?fnamestr:stringcss=letctx=T.string_ctx?fnamestrinletparser=Vp.handle_endSp.statementsctxinmatchAngstrom.parse_string~consume:Angstrom.Consume.Allparserstrwith|Okv->v|Errormsg->T.error(T.Parse_error(None,T.Othermsg))(** Namespaces map strings to IRIs. *)typenamespaces=Iri.tT.Smap.t(** [expand_ns css] expands the namespaces in the given [css], according
to the namespace statements in [css]. Some predefined namespaces
can be given with [ns] optional argument. If not specified, the
{{!S.default_ns}default namespaces} are used.*)letexpand_ns:?ns:namespaces->stringcss->Iri.tcss=S.expand_statement_list(** Pretty-print the given (non-expanded) CSS to the given formatter. *)letpp_string_css:Format.formatter->stringcss->unit=letto_s=function|("",s)->s|(ns,s)->Printf.sprintf"%s|%s"nssinS.pp_statement_listto_s(** Pretty-print the given (expanded) CSS to the given formatter. *)letpp_iri_css:Format.formatter->Iri.tcss->unit=letto_s(iri,s)=matchIri.to_stringiriwith|""->s|iri->Printf.sprintf"%s|%s"irisinS.pp_statement_listto_s(** See {!C.compute_decls}. *)letcompute_decls=C.compute_decls