123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161(*
* This file originates from OCamlFormat.
*
* Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*)openCompat(* original modules *)moduleAsttypes_=AsttypesmoduleParsetree_=Parsetreeinclude(Migrate_parsetree.Ast_408:moduletypeofstructincludeMigrate_parsetree.Ast_408endwithmoduleLocation:=Migrate_parsetree.Ast_408.LocationandmoduleOutcometree:=Migrate_parsetree.Ast_408.OutcometreeandmoduleAsttypes:=Migrate_parsetree.Ast_408.AsttypesandmoduleAst_helper:=Migrate_parsetree.Ast_408.Ast_helperandmoduleParsetree:=Migrate_parsetree.Ast_408.Parsetree)moduleAsttypes=Migrate_parsetree.Ast_408.AsttypesmoduleAst_helper=Migrate_parsetree.Ast_408.Ast_helpermoduleParsetree=Migrate_parsetree.Ast_408.ParsetreemoduleParse=structopenMigrate_parsetreelettoplevel_phraselexbuf=Parse.toplevel_phraseVersions.ocaml_408lexbufletimplementationlexbuf=Parse.implementationVersions.ocaml_408lexbufletinterfacelexbuf=Parse.interfaceVersions.ocaml_408lexbufendletto_current=Migrate_parsetree.Versions.(migrateocaml_408ocaml_current)letto_408=Migrate_parsetree.Versions.(migrateocaml_currentocaml_408)moduleTypemod=structopenTypemodlettype_structureesl=type_structuree(to_current.copy_structures)lendmodulePrintast=structopenPrintastlettop_phrasefx=top_phrasef(to_current.copy_toplevel_phrasex)endmodulePprintast=structopenPprintastlettop_phrasefx=top_phrasef(to_current.copy_toplevel_phrasex)endmodulePrinttyp=structincludePrinttypletwrap_printing_envef=wrap_printing_env#if(OCAML_MAJOR=4&&OCAML_MINOR>=7)||OCAML_MAJOR>4~error:false#endifefendmodulePparse=structopenPparseletapply_rewriters_str~tool_names=apply_rewriters_str~tool_name(to_current.copy_structures)|>to_408.copy_structureendmodulePosition=structopenLexingletcolumn{pos_fname=_;pos_lnum=_;pos_bol;pos_cnum}=pos_cnum-pos_bolletfmtfs{pos_fname=_;pos_lnum;pos_bol;pos_cnum}=ifpos_lnum=-1thenFormat.fprintffs"[%d]"pos_cnumelseFormat.fprintffs"[%d,%d+%d]"pos_lnumpos_bol(pos_cnum-pos_bol)letcompare_colp1p2=(columnp1)-(columnp2)letequalp1p2=String.equalp1.pos_fnamep2.pos_fname&&p1.pos_lnum=p2.pos_lnum&&p1.pos_bol=p2.pos_bol&&p1.pos_cnum=p2.pos_cnumletcomparep1p2=ifequalp1p2then0elsep1.pos_cnum-p2.pos_cnumletdistancep1p2=p2.pos_cnum-p1.pos_cnumendmoduleLocation=structincludeMigrate_parsetree.Ast_408.Locationletfmtfs{loc_start;loc_end;loc_ghost}=Format.fprintffs"(%a..%a)%s"Position.fmtloc_startPosition.fmtloc_end(ifloc_ghostthen" ghost"else"")letto_stringx=Format.asprintf"%a"fmtxletcomparexy=letcompare_start=Position.comparex.loc_starty.loc_startinifcompare_start=0thenPosition.comparex.loc_endy.loc_endelsecompare_startlethash=Hashtbl.hashletis_single_linex=x.loc_start.pos_lnum=x.loc_end.pos_lnumletcompare_startxy=Position.comparex.loc_starty.loc_startletcompare_start_colxy=Position.compare_colx.loc_starty.loc_startletcompare_endxy=Position.comparex.loc_endy.loc_endletcompare_end_colxy=Position.compare_colx.loc_endy.loc_endletcontainsl1l2=compare_startl1l2<=0&&compare_endl1l2>=0letwidthx=Position.distancex.loc_startx.loc_endletcompare_width_decreasingl1l2=(widthl2)-(widthl1)end