[wg-camlp4] expressions in pattern position ?

Nicolas Ojeda Bar no263 at dpmms.cam.ac.uk
Wed Apr 22 17:36:11 BST 2015


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


More information about the wg-camlp4 mailing list