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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4FAA9D17E for ; Tue, 26 Jul 2005 03:18:58 +0200 (CEST) Received: from salzburg.ucdavis.edu (salzburg.ucdavis.edu [169.237.104.162]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6Q1IuVm007168 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 26 Jul 2005 03:18:57 +0200 Received: from [169.237.7.95] (puck.cs.ucdavis.edu [169.237.7.95]) by salzburg.ucdavis.edu (8.13.3/8.13.1/it-defang-5.4.0) with ESMTP id j6Q1IsZj003244; Mon, 25 Jul 2005 18:18:54 -0700 (PDT) Message-ID: <42E58F35.8070204@crans.org> Date: Mon, 25 Jul 2005 18:17:41 -0700 From: Stephane Glondu User-Agent: Debian Thunderbird 1.0.2 (X11/20050331) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Paul Snively Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question re: camlp4 parser References: <3FA9259E-584B-45D7-BACD-A648222E5A0B@mac.com> In-Reply-To: <3FA9259E-584B-45D7-BACD-A648222E5A0B@mac.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.49 on 169.237.104.162 X-Miltered: at concorde with ID 42E58F80.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 parser:01 parser:01 rec:01 val:01 char:01 buf:01 buffer:01 rec:01 buffer:01 char:01 buf:01 val:01 wrote: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.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Paul Snively wrote: > For example, I'd like a parser that matches one or more printable ASCII > characters. Something that looks like: > > let rec printable = parser [< '' '..'~'; x = printable >] -> x The inferred type should have given you a warning: --> val printable : char Stream.t -> 'a = In other word, your function never returns a correct value. Try this: let printable s = let buf = Buffer.create 100 in let rec aux = parser [< '' '..'~' as c; x = (Buffer.add_char buf c; aux) >] -> x | [< >] -> Buffer.contents buf in aux s ;; --> val printable : char Stream.t -> string = printable (Stream.of_string "Test!\013") ;; --> - : string = "Test!" Notice that you cannot remove the occurrences of "s" (even though it would have the same type) if you are planning to use this function several times. > Many thanks and best regards, You're welcome. -- Stephane Glondu.