English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Stream parser/make_lexer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-06-26 (10:12)
From: Sen Horak <sen.horak@g...>
Subject: Stream parser/make_lexer

I tried building a small parser using Genlexer.make_parser and the
stream parser through the camlp4 preprocessor. I'm using the ocaml
compiler 3.08.1.

let lexer=make_lexer ["begin";"end";...]

let parse = parser
      [<'Kwd "name=";'String t>] -> wm#setname t
  |  ...

let istream = of_channel stdin

let ilexer = lexer istream in
  parse ilexer

The program exits with a Stream.Failure exception. The "stream
builders" documentation clearly says that we are not to mix the of_*
functions to build streams with <> streams - so I guess this is
expected. Although I've come across some examples that use of_string
to build the char stream and use the lexer on it.

How then does one build a stream compatible with the stream parser
connected to stdin?

Also, is the make_lexer/stream parser way of building a parser
deprecated? I find it a convenient way to build small parsers quickly.
Or do most ocaml programmers just use ocamllex/ocamlyacc for