123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(*
* Copyright (c) 2018 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* 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.
*)openResulttypesyntax=Cmt|Attrtypepart_begin={indent:string;payload:string}typet=Part_beginofsyntax*part_begin|Part_endmoduleRegexp=structletmarker=Re.str"$MDX"letspaces=Re.rep1Re.spaceletid=Re.(rep1(alt[alnum;char'_';char'-';char'=']))letcmt=letopenReincompile@@seq[group(repspace);str"(*";spaces;marker;spaces;groupid;spaces;str"*)";]letattribute=letopenReinletws=repspaceincompile@@whole_string@@seq[groupws;str"[@@@";ws;groupid;ws;str"\"";groupid;str"\"";ws;str"]";ws;opt(str";;");ws;]endletparse_attrline=matchRe.exec_optRegexp.attributelinewith|Someg->(letindent=Re.Group.getg1inletname=Re.Group.getg2inletpayload=Re.Group.getg3inmatchnamewith|"part"->Some(Part_begin(Attr,{indent;payload}))|_->None)|None->Noneletparse_cmtline=matchRe.exec_optRegexp.cmtlinewith|Someg->(letindent=Re.Group.getg1inmatchRe.Group.getg2with|"part-end"->Ok(SomePart_end)|s->(matchAstring.String.cut~sep:"="swith|Some("part-begin",payload)->Ok(Some(Part_begin(Cmt,{indent;payload})))|Some("part-end",_)->Util.Result.errorf"'part-end' delimiter does not accept a value. Please write \
'(* $MDX part-end *)' instead."|_->Util.Result.errorf"'%s' is not a valid ocaml delimiter for mdx."line))|None->OkNoneletparseline=matchparse_attrlinewith|Somedelimiter->Ok(Somedelimiter)|None->parse_cmtline