<div dir="ltr">Another option you have is to only replace the part that cannot be patterns by extensions:<br><br>match%bitstring bits with<br>
| { len = [%p <expr>]; bind = [%p <expr>] } -> ...<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 22, 2015 at 6:36 PM, Nicolas Ojeda Bar <span dir="ltr"><<a href="mailto:no263@dpmms.cam.ac.uk" target="_blank">no263@dpmms.cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I am currently working on porting ocaml-bitstring to ppx.<br>
<br>
<<a href="https://code.google.com/p/bitstring/" target="_blank">https://code.google.com/p/bitstring/</a>><br>
<br>
The camlp4 version of this syntax extension extends the syntax to allow<br>
expressions in "pattern" positions.  For example:<br>
<br>
bitmatch bits with<br>
| { <patt> : <expr> : bind <expr> } -> ...<br>
<br>
I am considering the following concrete ppx syntax to emulate this:<br>
<br>
match%bitstring bits with<br>
| x, [%len <expr>], [%bind <expr>] -><br>
<br>
(the [%len] annotation can be skipped if the payload is a literal constant).<br>
<br>
I find this syntax a little too heavy and am thinking about ways to improve it.<br>
<br>
I seem to remember some time ago there was a discussion about having the parser<br>
allow expression in pattern positions and reject those which are not<br>
patterns during<br>
typechecking.  I don't actually like this option, but was wondering if<br>
there had been any<br>
conclusions on the issue.<br>
<br>
Another possibility would be to use the {| ... |} annotation, as in:<br>
<br>
match%bitstring bits with<br>
| {| x : <expr> : bind <expr> |} -> ...<br>
<br>
The problem then is that one needs to write a parser for the thing<br>
inside {| ... |}.  I thought<br>
about splitting the payload on the delimiter ':' and then calling the<br>
OCaml parser to parse<br>
the individual subparts (here: "x", "<expr>", and "bind <expr>").<br>
<br>
What do you think ?<br>
<br>
Thanks!<br>
<br>
Best wishes,<br>
Nicolas<br>
_______________________________________________<br>
wg-camlp4 mailing list<br>
<a href="mailto:wg-camlp4@lists.ocaml.org">wg-camlp4@lists.ocaml.org</a><br>
<a href="http://lists.ocaml.org/listinfo/wg-camlp4" target="_blank">http://lists.ocaml.org/listinfo/wg-camlp4</a><br>
</blockquote></div><br></div>