Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file mdx.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118(*
* 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.
*)letsrc=Logs.Src.create"ocaml-mdx"moduleLexer_mdx=Lexer_mdxmoduleLog=(valLogs.src_logsrc:Logs.LOG)moduleOutput=OutputmoduleCram=CrammoduleDeprecated=DeprecatedmoduleDocument=DocumentmoduleToplevel=ToplevelmoduleLibrary=LibrarymoduleOcaml_delimiter=Ocaml_delimitermodulePart=PartmoduleBlock=BlockmoduleMigrate_ast=Migrate_astmoduleMli_parser=Mli_parsermoduleCompat=CompatmoduleUtil=UtilmodulePrelude=PreludemoduleSyntax=SyntaxmoduleLabel=LabelmoduleDep=DepmoduleOcaml_env=Ocaml_envincludeDocumentopenUtil.Result.Infixletsection_of_line=function|Sections->Somes|Text_->None|Blockb->b.sectionletfilter_sectionre(t:t)=matchList.filter(funl->matchsection_of_linelwith|None->false|Some(_,s)->Re.execpres)twith|[]->None|l->Somelletparsel=List.map(function|`Textt->Textt|`Sections->Sections|`Blockb->Blockb)lletparse_lexbuffile_contentssyntaxl=matchsyntaxwith|Syntax.Mli->Mli_parser.parse_mlifile_contents|Normal->Lexer_mdx.markdown_tokenl>>|parse|Cram->Lexer_mdx.cram_tokenl>>|parseletparse_filesyntaxf=letl=snd(Misc.initf)inparse_lexbuffsyntaxlletof_stringsyntaxs=matchsyntaxwith|Syntax.Mli->Mli_parser.parse_mlis|Syntax.Normal|Syntax.Cram->parse_lexbufssyntax(Lexing.from_strings)letdump_lineppf(l:line)=matchlwith|Blockb->Fmt.pfppf"Block %a"Block.dumpb|Section(d,s)->Fmt.pfppf"Section (%d, %S)"ds|Texts->Fmt.pfppf"Text %S"sletdump=Fmt.Dump.listdump_linetypeexpect_result=Identical|Differsletrun_str~syntax~ffile=letfile_contents,lexbuf=Misc.initfileinparse_lexbuffile_contentssyntaxlexbuf>>|funitems->Log.debug(funl->l"run @[%a@]"dumpitems);letcorrected=ffile_contentsitemsinlethas_changed=corrected<>file_contentsinletresult=ifhas_changedthenDifferselseIdenticalin(result,corrected)letwrite_file~outfilecontent=letoc=open_out_binoutfileinoutput_stringoccontent;close_outocletrun_to_stdout?(syntax=Normal)~finfile=run_str~syntax~finfile>>|fun(_,corrected)->print_stringcorrectedletrun_to_file?(syntax=Normal)~f~outfileinfile=run_str~syntax~finfile>>|fun(_,corrected)->write_file~outfilecorrectedletrun?(syntax=Normal)?(force_output=false)~finfile=letoutfile=infile^".corrected"inrun_str~syntax~finfile>>|fun(test_result,corrected)->match(force_output,test_result)with|true,_|false,Differs->write_file~outfilecorrected|false,Identical->ifSys.file_existsoutfilethenSys.removeoutfile