[wg-camlp4] expressions in pattern position ?

Gabriel Scherer gabriel.scherer at gmail.com
Wed Apr 22 17:51:50 BST 2015


Another option you have is to only replace the part that cannot be patterns
by extensions:

match%bitstring bits with
| { len = [%p <expr>]; bind = [%p <expr>] } -> ...

On Wed, Apr 22, 2015 at 6:36 PM, Nicolas Ojeda Bar <no263 at dpmms.cam.ac.uk>
wrote:

> Hi,
>
> I am currently working on porting ocaml-bitstring to ppx.
>
> <https://code.google.com/p/bitstring/>
>
> The camlp4 version of this syntax extension extends the syntax to allow
> expressions in "pattern" positions.  For example:
>
> bitmatch bits with
> | { <patt> : <expr> : bind <expr> } -> ...
>
> I am considering the following concrete ppx syntax to emulate this:
>
> match%bitstring bits with
> | x, [%len <expr>], [%bind <expr>] ->
>
> (the [%len] annotation can be skipped if the payload is a literal
> constant).
>
> I find this syntax a little too heavy and am thinking about ways to
> improve it.
>
> I seem to remember some time ago there was a discussion about having the
> parser
> allow expression in pattern positions and reject those which are not
> patterns during
> typechecking.  I don't actually like this option, but was wondering if
> there had been any
> conclusions on the issue.
>
> Another possibility would be to use the {| ... |} annotation, as in:
>
> match%bitstring bits with
> | {| x : <expr> : bind <expr> |} -> ...
>
> The problem then is that one needs to write a parser for the thing
> inside {| ... |}.  I thought
> about splitting the payload on the delimiter ':' and then calling the
> OCaml parser to parse
> the individual subparts (here: "x", "<expr>", and "bind <expr>").
>
> What do you think ?
>
> Thanks!
>
> Best wishes,
> Nicolas
> _______________________________________________
> wg-camlp4 mailing list
> wg-camlp4 at lists.ocaml.org
> http://lists.ocaml.org/listinfo/wg-camlp4
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/wg-camlp4/attachments/20150422/ba48484d/attachment.html>


More information about the wg-camlp4 mailing list