123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172(* Yoann Padioleau
*
* Copyright (C) 2019 r2c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL)
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* file license.txt for more details.
*)moduleJ=Json_typemodulePI=Parse_infomoduleE=Error_code(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*****************************************************************************)(* JSON *)(*****************************************************************************)(* copy-paste: checked_return.ml *)letloc_to_json_rangeloc=(* pfff (and Emacs) have the first column at index 0, but not r2c *)letadjust_columnx=x+1inJ.Object["line",J.Intloc.PI.line;"col",J.Int(adjust_columnloc.PI.column);],J.Object["line",J.Intloc.PI.line;"col",J.Int(adjust_column(loc.PI.column+String.lengthloc.PI.str));],loc.PI.linelethcache=Hashtbl.create101letlines_of_file(file:Common.filename):stringarray=Common.memoizedhcachefile(fun()->tryCommon.catfile|>Array.of_listwith_->[|"EMPTY FILE"|])leterror_to_jsonchecker_iderr=letfile=err.E.loc.PI.fileinletlines=lines_of_filefileinlet(startp,endp,line)=loc_to_json_rangeerr.E.locinletmessage=E.string_of_error_kinderr.E.typinletextra_extra=matcherr.E.typwith|_->[]inJ.Object["check_id",J.Stringchecker_id;"path",J.Stringfile;"start",startp;"end",endp;"extra",J.Object(["message",J.Stringmessage;"line",J.String(trylines.(line-1)with_->"NO LINE");]@extra_extra);]letstring_of_errorschecker_iderrs=letarr=J.Array(errs|>List.map(error_to_jsonchecker_id))inletjson=J.Object["results",arr]inJson_io.string_of_jsonjson