Open just-max opened 1 year ago
Hello and thanks for the issue!
Unfortunately, I have very few time to allocate to ppxlib, and most of it is already taken by the modifications to the parsetree.
At first sight, your proposition seems a good improvement, and I've seen other people facing the same problem; and having to come up with a similar solution (ping @EmileTrotignon).
So, we will try to review your proposition to include this in the library in a not too distant future, but don't expect too much reactivity, at least from me... Apologies in advance!
Lets say we wanted to implement a pattern that takes a module type of the form
and parses it to a list of the functor arguments, followed by the core module type, of the form:
Here's a simple implementation that's not quite right:
This would work, but the strict nature of OCaml means this does nothing but run in circles.
Instead, a
fix
combinator may be added toAst_pattern
:Then, the definition of
strip_functors
becomes:This terminates just fine!
Here's a possible implementation for
fix
:Here's an example that doesn't just pass
()
to the recursive call, and searches for alet
binding with the given name to a maximum depth:Inspired partly by QCheck.
With an implementation for
bind : ('a, 'b -> 'c, 'd) t -> f:('b -> ('a, 'e, 'c) t) -> ('a, 'e, 'd) t
, the recursive parser can depend on parsed values:Here is such an implementation:
Finally, this combinator might be useful:
I think
fix
andbind
would both be very useful for writing general patterns. The performance offix
should be acceptable, but withbind
there comes the risk of an explosion of search paths if one is not careful, given the backtracking implementation of the parser.Is there any desire to have these included in the library?