[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Anastasia Gornostaeva <ermine@e...> |
| Subject: | Re: [Caml-list] unix.select + camlp4 |
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 = <abstr>
> # 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