Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file Docstring.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158(**************************************************************************)(* *)(* OCamlFormat *)(* *)(* Copyright (c) Facebook, Inc. and its affiliates. *)(* *)(* This source code is licensed under the MIT license found in *)(* the LICENSE file in the root directory of this source tree. *)(* *)(**************************************************************************)letparse~loctext=letlocation=loc.Location.loc_startinletlocation={locationwithpos_cnum=location.pos_cnum+3(* Length of comment opening *)}inletv=Odoc_parser.parse_comment~location~textinmatchOdoc_parser.warningsvwith|[]->Ok(Odoc_parser.astv)|warnings->Errorwarningsletparse_filelocationtext=Odoc_parser.ast(Odoc_parser.parse_comment~location~text)letwarnfmtwarning=Format.fprintffmt"Warning: Invalid documentation comment:@,%s\n%!"(Odoc_parser.Warning.to_stringwarning)letis_tag_only=List.for_all~f:(function|{Odoc_parser.Loc.value=`Tag_;_}->true|_->false)typenorm_conf={normalize_code:string->string}letnormalize_texts=(* normalize consecutive whitespace chars to a single space *)String.concat~sep:" "(List.filter~f:(Fn.nonString.is_empty)(String.split_on_charss~on:['\t';'\n';'\011';'\012';'\r';' ']))letlistffmtl=letpp_sepfmt()=Format.fprintffmt""inFormat.pp_print_list~pp_sepffmtlletstrfmts=Format.fprintffmt"%s"(normalize_texts)letign_locffmtwith_loc=ffmtwith_loc.Odoc_parser.Loc.valueletfpf=Format.fprintfletodoc_reference=ign_locstrletoptionffmt=functionSomev->ffmtv|None->()letpairfmt_afmt_bfmt(a,b)=fpffmt"(%a,%a)"fmt_aafmt_bbletodoc_stylefmt=function|`Bold->fpffmt"Bold"|`Italic->fpffmt"Italic"|`Emphasis->fpffmt"Emphasis"|`Superscript->fpffmt"Superscript"|`Subscript->fpffmt"Subscript"letrecodoc_inline_elementfmt=function|`Space_->()|`Wordtxt->(* Ignore backspace changes *)lettxt=String.filtertxt~f:(function'\\'->false|_->true)infpffmt"Word(%a)"strtxt|`Code_spantxt->fpffmt"Code_span(%a)"strtxt|`Math_spantxt->fpffmt"Math_span(%a)"strtxt|`Raw_markup(Somelang,txt)->fpffmt"Raw_markup(%s,%a)"langstrtxt|`Raw_markup(None,txt)->fpffmt"Raw_markup(%a)"strtxt|`Styled(style,elems)->fpffmt"Styled(%a,%a)"odoc_stylestyleodoc_inline_elementselems|`Reference(_kind,ref,content)->fpffmt"Reference(%a,%a)"odoc_referencerefodoc_inline_elementscontent|`Link(txt,content)->fpffmt"Link(%a,%a)"strtxtodoc_inline_elementscontentandodoc_inline_elementsfmtelems=list(ign_locodoc_inline_element)fmtelemsletrecodoc_nestable_block_elementcfmt=function|`Paragraphelms->fpffmt"Paragraph(%a)"odoc_inline_elementselms|`Code_block(metadata,txt)->lettxt=Odoc_parser.Loc.valuetxtinlettxt=c.normalize_codetxtinletfmt_metadata=option(pair(ign_locstr)(option(ign_locstr)))infpffmt"Code_block(%a, %a)"fmt_metadatametadatastrtxt|`Math_blocktxt->fpffmt"Math_block(%a)"strtxt|`Verbatimtxt->fpffmt"Verbatim(%a)"strtxt|`Modulesmods->fpffmt"Modules(%a)"(listodoc_reference)mods|`List(ord,_syntax,items)->letord=matchordwith`Unordered->"U"|`Ordered->"O"inletlist_itemfmtelems=fpffmt"Item(%a)"(odoc_nestable_block_elementsc)elemsinfpffmt"List(%s,%a)"ord(listlist_item)itemsandodoc_nestable_block_elementscfmtelems=list(ign_loc(odoc_nestable_block_elementc))fmtelemsletodoc_tagcfmt=function|`Authortxt->fpffmt"Author(%a)"strtxt|`Deprecatedelems->fpffmt"Deprecated(%a)"(odoc_nestable_block_elementsc)elems|`Param(p,elems)->fpffmt"Param(%a,%a)"strp(odoc_nestable_block_elementsc)elems|`Raise(p,elems)->fpffmt"Raise(%a,%a)"strp(odoc_nestable_block_elementsc)elems|`Returnelems->fpffmt"Return(%a)"(odoc_nestable_block_elementsc)elems|`See(kind,txt,elems)->letkind=matchkindwith`Url->"U"|`File->"F"|`Document->"D"infpffmt"See(%s,%a,%a)"kindstrtxt(odoc_nestable_block_elementsc)elems|`Sincetxt->fpffmt"Since(%a)"strtxt|`Before(p,elems)->fpffmt"Before(%a,%a)"strp(odoc_nestable_block_elementsc)elems|`Versiontxt->fpffmt"Version(%a)"strtxt|`Canonicalref->fpffmt"Canonical(%a)"odoc_referenceref|`Inline->fpffmt"Inline"|`Open->fpffmt"Open"|`Closed->fpffmt"Closed"letodoc_block_elementcfmt=function|`Heading(lvl,lbl,content)->letlvl=Int.to_stringlvlinletlbl=matchlblwithSomelbl->lbl|None->""infpffmt"Heading(%s,%a,%a)"lvlstrlblodoc_inline_elementscontent|`Tagtag->fpffmt"Tag(%a)"(odoc_tagc)tag|#Odoc_parser.Ast.nestable_block_elementaselm->odoc_nestable_block_elementcfmtelmletodoc_docscfmtelems=list(ign_loc(odoc_block_elementc))fmtelemsletnormalize~parse_docstrings~normalize_codetext=ifnotparse_docstringsthennormalize_texttextelseletlocation=Lexing.dummy_posinletparsed=Odoc_parser.parse_comment~location~textinletc={normalize_code}inFormat.asprintf"Docstring(%a)%!"(odoc_docsc)(Odoc_parser.astparsed)letdumpfmtx=letc={normalize_code=Fn.id}inFormat.fprintffmt"Docstring(%a)%!"(odoc_docsc)x