123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(* YOCaml a static blog generator.
Copyright (C) 2024 The Funkyworkers and The YOCaml's developers
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, either version 3 of the License, or
(at your option) any later version.
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, see <https://www.gnu.org/licenses/>. *)typet=Sexp.tleterror_to_string=function|Sexp.Nonterminated_nodex->Format.asprintf"non-terminated node on [%d]"x|Nonterminated_atomx->Format.asprintf"non-terminated atom on [%d]"x|Unexepected_character(c,x)->Format.asprintf"unexpected character [%c] on [%d]"cx|Expected_number_or_colon(c,x)->Format.asprintf"expected number or colon on [%d], given: [%c]"xc|Expected_number(c,x)->Format.asprintf"expected number on [%d], given: [%c]"xc|Premature_end_of_atom(len,x)->Format.asprintf"premature end of atom, expected length [%d] on [%d]"lenxletfrom_stringstr=str|>Sexp.from_string|>Result.map_error(funerror->letgiven=strinletmessage=error_to_stringerrorinRequired.Parsing_error{given;message})let(<|>)ab=match(a,b)withSomex,_->Somex|None,Somey->Somey|_->Noneletnormalize_atomx=bool_of_string_optx|>Option.mapData.bool<|>(int_of_string_optx|>Option.mapData.int)<|>(float_of_string_optx|>Option.mapData.float)|>Option.value~default:(Data.stringx)letis_record=List.for_all(functionSexp.Node[Atom_;_]->true|_->false)letrecnormalize=function|Sexp.Atomx->normalize_atomx|Node[]->Data.list[]|Nodenodewhenis_recordnode->Data.record(List.concat_map(function|Sexp.Node[Atomk;value]->[(k,normalizevalue)]|_(* not reachable *)->[])node)|Nodenode->Data.list_ofnormalizenode