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.8 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id B5FB3BC69 for ; Sun, 1 Jul 2007 23:01:25 +0200 (CEST) Received: from home.mk.pp.ru (av6800.comex.ru [217.10.34.155]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l61L1PIp022599 for ; Sun, 1 Jul 2007 23:01:25 +0200 Received: from ermine.home (ermine.home [192.168.2.2]) by home.mk.pp.ru (Postfix) with ESMTP id 01E0820A1D for ; Mon, 2 Jul 2007 01:01:24 +0400 (MSD) Received: by ermine.home (Postfix, from userid 1000) id 13A931B5839; Mon, 2 Jul 2007 01:01:25 +0400 (MSD) Date: Mon, 2 Jul 2007 01:01:25 +0400 From: Anastasia Gornostaeva To: caml-list@inria.fr Subject: Re: [Caml-list] unix.select + camlp4 Message-ID: <20070701210125.GB4434@ermine.home> References: <20070701203044.GA4434@ermine.home> <200707012137.46921.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <200707012137.46921.jon@ffconsultancy.com> User-Agent: Mutt/1.5.15 (2007-04-06) X-Miltered: at discorde with ID 46881625.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 0100,:01 camlp:01 parser:01 expr:01 expr:01 val:01 abstr:01 mult:01 mult:01 parses:01 non-blocking:01 parser:01 parsing:01 parsing:01 On Sun, Jul 01, 2007 at 09:37:46PM +0100, Jon Harrop wrote: > > Is it possible to use camlp4-based parser with data which comes from > > Unix.select input? Read a line, parse it, if a line was incomplete to parse > > then save a state, continue.... How do to do it? > > Bruno gave an excellent example of parsing strings using camlp4, posted on > 22/06/2007: > > # open Camlp4.PreCast ;; > # let expr = Gram.Entry.mk "expr" ;; > val expr : '_a Camlp4.PreCast.Gram.Entry.t = > # EXTEND Gram > expr: > [ "add" LEFTA > [ e1 = expr; "+"; e2 = expr -> e1 +: e2 > | e1 = expr; "-"; e2 = expr -> e1 -: e2 ] > | "mult" LEFTA > [ e1 = expr; "*"; e2 = expr -> e1 *: e2 ] > | "simple" NONA > [ n = INT -> Num(int_of_string n) > | "("; e = expr; ")" -> e ] ] > ; > END ;; > - : unit = () > # Gram.parse expr Loc.ghost (Stream.of_string "1-2+3*4") ;; > - : expr = Add (Sub (Num 1, Num 2), Mult (Num 3, Num 4)) > > If you can read a line from Unix.select then you should be able to feed it > into this. I dont understand: Try: 1) It receives "1-2+3*" and parses it. 2) Later it receives "4" and continues parsing. I want to get non-blocking parser. How to implement? ermine