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 A42F2D179 for ; Tue, 26 Jul 2005 19:05:29 +0200 (CEST) Received: from 26.mail-out.ovh.net (26.mail-out.ovh.net [213.186.42.179]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6QH5TpK002584 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 26 Jul 2005 19:05:29 +0200 Received: (qmail 6930 invoked by uid 503); 26 Jul 2005 17:05:31 -0000 Received: (QMFILT: 1.0); 26 Jul 2005 17:05:31 -0000 Received: from b6.ovh.net (HELO mail12.ha.ovh.net) (213.186.33.56) by 26.mail-out.ovh.net with DES-CBC3-SHA encrypted SMTP; 26 Jul 2005 17:05:31 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 26 Jul 2005 17:05:26 -0000 Received: from mail12.ha.ovh.net (10.0.50.12) by mail12.ha.ovh.net with SMTP; 26 Jul 2005 17:05:23 -0000 Received: from b0.ovh.net (HELO queue-pre) (213.186.33.50) by b0.ovh.net with SMTP; 26 Jul 2005 17:05:23 -0000 Received: from ppp-69-228-105-144.dsl.scrm01.pacbell.net (HELO trantor.glondu.net) (postmaster%glondu.net@69.228.105.144) by ns0.ovh.net with SMTP; 26 Jul 2005 17:05:23 -0000 From: Stephane Glondu Organization: Crans To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question re: camlp4 parser Date: Tue, 26 Jul 2005 10:05:20 -0700 User-Agent: KMail/1.7.1 Cc: Paul Snively References: <3FA9259E-584B-45D7-BACD-A648222E5A0B@mac.com> <42E58F35.8070204@crans.org> <0C774C67-0FD2-49F3-9293-B81BB3A0991E@mac.com> 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: 7bit Content-Disposition: inline Message-Id: <200507261005.20779.Stephane.Glondu@crans.org> X-Ovh-Remote: 69.228.105.144 (ppp-69-228-105-144.dsl.scrm01.pacbell.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Miltered: at nez-perce with ID 42E66D59.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 parser:01 variants:01 buf:01 buffer:01 rec:01 parser:01 buffer:01 buf:01 char:01 usr:01 ...:98 wrote:01 avoids:01 printable:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 On Tuesday 26 July 2005 09:43, Paul Snively wrote: > One hopefully final question: is there a convenient shorthand for > saying something like "all printable characters except '=' 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 - '='" that that will match all > printable characters other than '='. I don't know whether there is a way to do this directly. You can split your range so that it avoids '=' and '[', or do something like this: let printable s = let buf = Buffer.create 100 in let rec aux = parser [< ' ('=' | '[') >] -> Buffer.contents buf | [< '' '..'~' as c; x = (Buffer.add_char buf c; aux) >] -> x | [< >] -> Buffer.contents buf in aux s ;; printable (Stream.of_string "path=/usr/src") ;; --> - : string = "path" Bear in mind that the '=' or '?' will be discarded by the parser. If you don't want so, you can use Stream.peek (but it's much more annoying). -- Stephane Glondu.