From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id D85FDD179 for ; Wed, 27 Jul 2005 09:04:08 +0200 (CEST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6R748fF008559 for ; Wed, 27 Jul 2005 09:04:08 +0200 Received: by wproxy.gmail.com with SMTP id i25so121999wra for ; Wed, 27 Jul 2005 00:04:07 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=kxnfSJYfSRXdElTW1Hcm8dA79XSUgPeOPApOnD0gV0w/tkU3tb9UAGtAIftqcCdxRess6uYbD4F2hJVR0HDNtiMElFwUP0z1it0zWWXZcIBM6hYipBov+JbomMMx8CtXqNVGXqLeeubUn8H0zKS2o4BsIMYVOdeleK2eRskedYE= Received: by 10.54.30.50 with SMTP id d50mr223384wrd; Wed, 27 Jul 2005 00:04:07 -0700 (PDT) Received: by 10.54.143.17 with HTTP; Wed, 27 Jul 2005 00:04:07 -0700 (PDT) Message-ID: <2787337705072700045a275ce6@mail.gmail.com> Date: Wed, 27 Jul 2005 09:04:07 +0200 From: Virgile Prevosto Reply-To: virgile.prevosto@m4x.org To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question re: camlp4 parser In-Reply-To: <0C774C67-0FD2-49F3-9293-B81BB3A0991E@mac.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <3FA9259E-584B-45D7-BACD-A648222E5A0B@mac.com> <42E58F35.8070204@crans.org> <0C774C67-0FD2-49F3-9293-B81BB3A0991E@mac.com> X-Miltered: at nez-perce with ID 42E731E8.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 parser:01 variants:01 'when':01 buf:01 buffer:01 rec:01 parser:01 buffer:01 char:01 buf:01 char:01 bool:01 26,:98 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 2005/7/26, Paul Snively : > One hopefully final question: is there a convenient shorthand for > saying something like "all printable characters except '=3D' or '['?" I > assume not--that is, we have ranges (' '..'~') or we have variants > ('A' | 'B' | 'C'...) and that's it. I'm somewhat spoiled, I think, by > Spirit in C++, and its notion of "character sets" and operations on > them, so I can say, e.g. "print_p - '=3D'" that that will match all > printable characters other than '=3D'. >=20 As any other pattern, stream patterns can be refined with a 'when' conditio= n: let printable s =3D let buf =3D Buffer.create 100 in let rec aux =3D parser | [< '' '..'~' as c when c <> '=3D' && c <> '[';=20 x =3D (Buffer.add_char buf c; aux) >] -> x | [< >] -> Buffer.contents buf in aux s ;; should do the trick. It might not be that convenient for a more complex set of excluded characters, but it is possible to write a char -> bool test outside of the stream parser. --=20 E tutto per oggi, a la prossima volta Virgile