From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 69028BBC4 for ; Mon, 13 Apr 2009 02:00:52 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwDAF8d4knIuX5DgWdsb2JhbACWMgEBFiKwV4N8Bg X-IronPort-AV: E=Sophos;i="4.40,177,1238968800"; d="scan'208";a="24471282" Received: from unknown (HELO mta20.f3.k8.com.br) ([200.185.126.67]) by mail2-smtp-roc.national.inria.fr with ESMTP; 13 Apr 2009 02:00:51 +0200 Received: from localhost (localhost [127.0.0.1]) by smtpa.f3.k8.com.br (Postfix) with ESMTP id 6DBC52800099 for ; Mon, 13 Apr 2009 00:00:47 +0000 (GMT) X-Virus-Scanned: amavisd-new at k8.com.br Received: from smtpa.f3.k8.com.br ([127.0.0.1]) by localhost (mta20.f3.k8.com.br [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ycDtIACDbdGr for ; Mon, 13 Apr 2009 00:00:47 +0000 (GMT) Received: from [189.106.62.108] (unknown [189.106.62.108]) by smtpa.f3.k8.com.br (Postfix) with ESMTP id 240C02800098 for ; Mon, 13 Apr 2009 00:00:46 +0000 (GMT) Subject: Camlp4 help From: Andre Nathan To: caml-list@inria.fr Content-Type: text/plain Date: Sun, 12 Apr 2009 21:05:59 -0300 Message-Id: <1239581159.6443.13.camel@homesick> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; camlp:01 forall:01 forall:01 syntax:01 expr:01 expr:01 impl:01 impl:01 camlp:01 nathan:98 constraint:01 int:01 int:01 expression:02 match:02 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