On Fri, 8 Jun 2007, roparzhhemon wrote:
> in the code below the stream "stream1" is empty. Why ? I should
> expect it to begin with
> Genlex.Kwd "type"; Genlex.Kwd"'"; Genlex.Ident"a" (...)
>
> let genlexer=Genlex.make_lexer
> ["+";"-";"*";"/";"=";"(";")";
> "let";"in";"if";"then";"else";
> "|";"||";";";";;";
> "type"];;
>
> let hlexer s=genlexer(Stream.of_string s);;
>
> let stream1=hlexer "type 'a option=None |Some of 'a";;
The stream is not empty. The first token is Kwd "type", as you expect:
# Stream.next stream1;;
- : Genlex.token = Genlex.Kwd "type"
This does not tell you what you think it does:
> Stream.count stream1;;
A result of 0 means no tokens have been read from the stream yet. Here is
the documentation for Stream.count, from stream.mli:
val count : 'a t -> int
(** Return the current count of the stream elements, i.e. the number
of the stream elements discarded. *)
You can use Stream.empty to test for an empty stream. It has a somewhat
strange behavior in that it returns () if the stream is empty and raises
Stream.Failure if not. You can also just read from the stream, which will
raise Stream.Failure on an empty stream.
Dave
.