From: Andre Nathan <andre@digirati.com.br>
To: caml-list@inria.fr
Subject: Camlp4 help
Date: Sun, 12 Apr 2009 21:05:59 -0300 [thread overview]
Message-ID: <1239581159.6443.13.camel@homesick> (raw)
Hello
I'm adding support for property testing in OSpec. Currently you can
write a specification like
forall (list_of int) (fun l -> (List.rev (List.rev l)) should = l)
and it's also possible to add a constraint as in
forall (list_of int) ~given:(fun l -> List.length l > 0)
(fun l -> l should match x::xs)
This automatically generates lists of random sizes containing random
elements, and runs the specified property for each of them. I've been
trying to turn this into a syntax extension that would look like
forall (list_of int) l . (List.rev (List.rev l)) should = l
or
forall (list_of int) l . List.length l > 0 => l should match x::xs
The best I could to to make this work was forcing parenthesis around the
expression that comes after the dot, with the following rule:
"forall"; "("; gen = expr; ")"; var = ipatt; "."; OPT "(";
e1 = expr; OPT ")"; impl = OPT "=>"; e2 = OPT expr ->
With that I can write the two specifications above as
forall (list_of int) l . ((List.rev (List.rev l)) should = l)
and
forall (list_of int) l . (List.length l > 0) => l should match x::xs
which is not that bad, but not exactly what I wanted...
If I simplify the rule above to
"forall"; "("; gen = expr; ")"; var = ipatt; ".";
e1 = expr; impl = OPT "=>"; e2 = OPT expr ->
then everything after the dot is bound to e1, even when there's a "=>".
Is there some other matcher in camlp4 other than "expr" that I could use
for that? If not, is there another way to parse this correctly without
the extra parenthesis?
Thanks in advance,
Andre
next reply other threads:[~2009-04-13 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-13 0:05 Andre Nathan [this message]
2009-04-13 19:08 ` [Caml-list] " Andre Nathan
-- strict thread matches above, loose matches on Subject: below --
2009-03-21 3:41 Andre Nathan
2005-07-15 8:39 camlp4 help Pietro Abate
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1239581159.6443.13.camel@homesick \
--to=andre@digirati.com.br \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox