123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960(**************************************************************************)(* *)(* Copyright 2013 OCamlPro *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the Lesser GNU Public License version 3.0. *)(* *)(* This software 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 *)(* Lesser GNU General Public License for more details. *)(* *)(**************************************************************************)(** Pops comments from a list of comments (string * loc) to find the ones that
are associated to a given location. Also returns the remaining comments after
the location. *)letassociate_comment~after_onlycommentslocnextloc=letlstart=loc.Location.loc_start.Lexing.pos_lnumandlend=loc.Location.loc_end.Lexing.pos_lnuminletisnextc=nextloc<>Location.none&&nextloc.Location.loc_start.Lexing.pos_cnum<c.Location.loc_end.Lexing.pos_cnuminletrecaux=function|[]->(None,[])|(comment,cloc)::comments->(letcstart=cloc.Location.loc_start.Lexing.pos_lnumandcend=cloc.Location.loc_end.Lexing.pos_lnuminletprocessed=(* It seems 4.02.3 remove ** from doc comment string, but not from
* locations. We can recognize doc comment by checking how the two
* differ. *)cloc.Location.loc_end.Lexing.pos_cnum-cloc.Location.loc_start.Lexing.pos_cnum=String.lengthcomment+5inifcend<lstart-1||(cstart<lend&&after_only)thenauxcommentselseifcstart>lend+1||isnextcloc||(cstart>lstart&&cend<lend(* keep inner comments *))then(None,(comment,cloc)::comments)elseifString.lengthcomment<2||((notprocessed)&&(comment.[0]<>'*'||comment.[1]='*'))thenauxcommentselseletcomment=ifprocessedthencommentelseString.subcomment1(String.lengthcomment-1)inletcomment=String.trimcommentinmatchauxcommentswith|None,comments->(Somecomment,comments)|Somec,comments->(Some(String.concat"\n"[comment;c]),comments))inauxcomments