From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] unix.select + camlp4
Date: Sun, 1 Jul 2007 21:37:46 +0100 [thread overview]
Message-ID: <200707012137.46921.jon@ffconsultancy.com> (raw)
In-Reply-To: <20070701203044.GA4434@ermine.home>
On Sunday 01 July 2007 21:30:44 Anastasia Gornostaeva 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.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e
next prev parent reply other threads:[~2007-07-01 20:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-01 20:30 Anastasia Gornostaeva
2007-07-01 20:37 ` Jon Harrop [this message]
2007-07-01 21:01 ` [Caml-list] " Anastasia Gornostaeva
2007-07-02 2:10 ` skaller
2007-07-02 10:06 ` Phd position at LACL, University of Paris 12 Frédéric Gava
2007-07-02 15:39 ` [Caml-list] unix.select + camlp4 Anastasia Gornostaeva
2007-07-02 16:44 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200707012137.46921.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox