Match a query against a sexp.
Calls f
once for every match found, passing the captured results in the format specified by output_method
as an argument.
wrap_mode
controls what happens when a capture consumes multiple sexps during a single match. It specifies whether to wrap them together as a single sexp list or return all the results separately.
For example: "(a %.*
)" tries to unwrap exactly one set of parens, match an 'a', and then capture all the sexps that follow that 'a'. Here are the three behaviors.
`Unwrap_always: (a) -> (* *) (a b) -> Sexp.Atom b
(* b *) (a b c) -> Sexp.Atom b; Sexp.Atom c
(* b c *)
`Wrap_non_singletons: (a) -> Sexp.List []
(* () *) (a b) -> Sexp.Atom b
(* b *) (a b c) -> Sexp.List [ Sexp.Atom b; Sexp.Atom c ]
(* (b c) *)
`Wrap_always: (a) -> Sexp.List []
(* () *) (a b) -> Sexp.List [ Sexp.Atom b ]
(* (b) *) (a b c) -> Sexp.List [ Sexp.Atom b; Sexp.Atom c ]
(* (b c) *)
This wrapping (or not) occurs before packing the result into whatever format specified by output_method
.