123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(**************************************************************************)(* *)(* 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. *)(* *)(**************************************************************************)openLongidentmoduleIndexing_op=structtyperaw={opchars:string;brackets:Asttypes.paren_kind;extended:bool(** eg. [.*{;..}] *);has_rhs:bool(** eg. [.*{}<-] *)}letparseident=matchString.chop_prefix~prefix:"."identwith|None->None|Someident->letident,has_rhs=matchString.chop_suffixident~suffix:"<-"with|Someident->(ident,true)|None->(ident,false)inletfind_suffix(suffix,brackets,extended)=matchString.chop_suffixident~suffixwith|None->None|Someopchars->Some{opchars;brackets;extended;has_rhs}inList.find_map~f:find_suffix[("{}",Asttypes.Brace,false);("[]",Bracket,false);("()",Paren,false);("{;..}",Brace,true);("[;..]",Bracket,true);("(;..)",Paren,true)]endmoduleChar_id=structletis_kwdop=function|'$'|'&'|'*'|'+'|'-'|'/'|'<'|'='|'>'|'@'|'^'|'|'|'!'|'%'|':'|'?'->true|_->falseletis_infixop=function|'$'|'%'|'*'|'+'|'-'|'/'|'<'|'='|'>'|'|'|'&'|'@'|'^'|'#'->true|_->falseendmoduleString_id=structletis_prefixi=matchiwith|"!="->false|_->(matchi.[0]with'!'|'?'|'~'->true|_->false)letis_monadic_bindings=String.lengths>3&&(String.is_prefixs~prefix:"let"||String.is_prefixs~prefix:"and")&&Option.is_none(String.lfindis~pos:3~f:(fun_c->not(Char_id.is_kwdopc)))letis_infixi=ifChar_id.is_infixopi.[0]thentrueelsematchiwith|"!="|"land"|"lor"|"lxor"|"mod"|"::"|":="|"asr"|"lsl"|"lsr"|"or"|"||"->true|_->is_monadic_bindingiletis_hash_getteri=letis_infix_charc=Char.equalc'.'||Char_id.is_infixopcinmatch(i.[0],i.[String.lengthi-1])with|'#',('#'|'.')whenString.for_alli~f:is_infix_char->true|_->falseletis_index_opident=Option.is_some(Indexing_op.parseident)letis_symboli=is_prefixi||is_infixi||is_index_opiendlettest~f=functionLongident.Lidenti->fi|_->falseletis_prefix=test~f:String_id.is_prefixletis_monadic_binding=test~f:String_id.is_monadic_bindingletis_infix=test~f:String_id.is_infixletis_hash_getter=test~f:String_id.is_hash_getterletis_index_opi=Longident.lasti|>String_id.is_index_opletis_symboli=is_prefixi||is_infixi||is_index_opiletfield_alias_str~fieldy=matchfieldwith|Ldot(_,x)|Lidentx->String.equalxy|Lapply_->falseletfield_alias~field=function|Lidentx->field_alias_str~fieldx|Ldot_|Lapply_->false