12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485open!CoremoduleFormat=structtypet=|Atomofstring|Captureofstring|Listoftlistletescape_percents=unstage(String.Escaping.escape~escapeworthy:['%']~escape_char:'\\');;letunescape_percents=unstage(String.Escaping.unescape~escape_char:'\\')letrect_of_sexpsexp=match(sexp:Sexp.t)with|Atoms->ifString.is_prefixs~prefix:"%"thenCapture(String.chop_prefix_exns~prefix:"%")elseAtom(unescape_percentss)|Listlist->List(List.maplist~f:t_of_sexp);;letrecsexp_of_tt:Sexp.t=matchtwith|Atoms->Atom(escape_percentss)|Captures->Atom("%"^s)|Listlist->List(List.maplist~f:sexp_of_t);;letts_of_strings=Sexp.scan_sexps(Lexing.from_strings)|>List.map~f:t_of_sexpletrecall_captures_auxtacc=matchtwith|Atom_->acc|Captures->s::acc|Listlist->List.fold_rightlist~init:acc~f:all_captures_aux;;letall_capturest=all_captures_auxt[]letrecembed_capturest~f:Sexp.tlist=matchtwith|Atoms->[Atoms]|Captures->fs|Listlist->[List(List.concat_maplist~f:(embed_captures~f))];;endmoduleWrap_mode=structtype'query_resultt=|Wrap_always:Sexp.tt|Wrap_non_singletons:Sexp.tt|Unwrap_always:Sexp.tlistt[@@derivingsexp_of]typesome_wrap_mode=T:_t->some_wrap_modeendtype'query_resultt=|Formats:_Wrap_mode.t*Format.tlist->Sexp.tlistt|List:'query_resultWrap_mode.t->Sexp.tt|Record:'query_resultWrap_mode.t->Sexp.tt|Single_capture:'query_resultWrap_mode.t->'query_resultt|Map:Sexp.tlistString.Map.tt(** Return a map from capture name to captures *)[@@derivingsexp_of]typesome_output_method=T:_t->some_output_methodletdefault_methodquery~wrap_mode=let{Query.Capture_count.num_number_captures;num_named_captures;num_unlabeled_captures}=Query.count_capturesqueryinifnum_named_captures>0thenT(Recordwrap_mode)elseifnum_number_captures>0||num_unlabeled_captures>1thenT(Listwrap_mode)elseifnum_unlabeled_captures=1thenT(Single_capturewrap_mode)elsefailwith"No captures % were specified in pattern";;