1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(* Yoann Padioleau
*
* Copyright (C) 2014 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library 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.
*)openCommonmodulePI=Parse_info(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* todo: extract and factorize more from comment_php.ml
*)(*****************************************************************************)(* Types *)(*****************************************************************************)(* todo: duplicate of matcher/parse_fuzzy.ml *)type'tokhooks={kind:'tok->Parse_info.token_kind;tokf:'tok->Parse_info.t;}(*****************************************************************************)(* Functions *)(*****************************************************************************)letcomment_beforehookstokall_toks=letpos=Parse_info.pos_of_infotokinletbefore=all_toks|>Common2.take_while(funtok2->letinfo=hooks.tokftok2inletpos2=PI.pos_of_infoinfoinpos2<pos)inletfirst_non_space=List.revbefore|>Common2.drop_while(funt->letkind=hooks.kindtinmatchkindwith|PI.EsthetPI.Newline|PI.EsthetPI.Space->true|_->false)inmatchfirst_non_spacewith|x::_xswhenhooks.kindx=*=PI.Esthet(PI.Comment)->letinfo=hooks.tokfxinifPI.col_of_infoinfo=0thenSomeinfoelseNone|_->Noneletcomment_afterhookstokall_toks=letpos=PI.pos_of_infotokinletline=PI.line_of_infotokinletafter=all_toks|>Common2.drop_while(funtok2->letinfo=hooks.tokftok2inletpos2=PI.pos_of_infoinfoinpos2<=pos)inletfirst_non_space=after|>Common2.drop_while(funt->letkind=hooks.kindtinmatchkindwith|PI.EsthetPI.Newline|PI.EsthetPI.Space->true|_->false)inmatchfirst_non_spacewith|x::_xswhenhooks.kindx=*=PI.Esthet(PI.Comment)->letinfo=hooks.tokfxin(* for ocaml comments they are not necessarily in
* column 0, but they must be just after
*)ifPI.line_of_infoinfo=line||PI.line_of_infoinfo=line+1(* && PI.col_of_info info > 0 *)thenSomeinfoelseNone|_->None