1995-11-09 03:04:31 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-11-09 03:04:31 -08:00
|
|
|
(* *)
|
|
|
|
(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1997-06-16 08:33:44 -07:00
|
|
|
(* Copyright 1997 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
1995-11-09 03:04:31 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Streams and parsers. *)
|
1995-11-09 03:04:31 -08:00
|
|
|
|
|
|
|
type 'a t
|
2001-12-03 14:16:03 -08:00
|
|
|
(** The type of streams holding values of type ['a]. *)
|
1995-11-09 03:04:31 -08:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
exception Failure
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Raised by parsers when none of the first components of the stream
|
|
|
|
patterns is accepted. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
exception Error of string
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Raised by parsers when the first component of a stream pattern is
|
|
|
|
accepted, but one of the following components is rejected. *)
|
1995-11-09 03:04:31 -08:00
|
|
|
|
|
|
|
|
2012-01-25 06:50:03 -08:00
|
|
|
(** {6 Stream builders} *)
|
2001-10-26 16:33:00 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val from : (int -> 'a option) -> 'a t
|
2001-10-26 16:33:00 -07:00
|
|
|
(** [Stream.from f] returns a stream built from the function [f].
|
|
|
|
To create a new stream element, the function [f] is called with
|
|
|
|
the current stream count. The user function [f] must return either
|
|
|
|
[Some <value>] for a value or [None] to specify the end of the
|
|
|
|
stream. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val of_list : 'a list -> 'a t
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return the stream holding the elements of the list in the same
|
|
|
|
order. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val of_string : string -> char t
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return the stream of the characters of the string parameter. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val of_channel : in_channel -> char t
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return the stream of the characters read from the input channel. *)
|
1995-11-09 03:04:31 -08:00
|
|
|
|
1995-11-10 07:15:12 -08:00
|
|
|
|
2001-12-28 15:15:04 -08:00
|
|
|
(** {6 Stream iterator} *)
|
2001-10-26 16:33:00 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val iter : ('a -> unit) -> 'a t -> unit
|
2001-10-26 16:33:00 -07:00
|
|
|
(** [Stream.iter f s] scans the whole stream s, applying function [f]
|
|
|
|
in turn to each stream element encountered. *)
|
1995-11-10 07:15:12 -08:00
|
|
|
|
|
|
|
|
2001-12-28 15:15:04 -08:00
|
|
|
(** {6 Predefined parsers} *)
|
2001-10-26 16:33:00 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val next : 'a t -> 'a
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return the first element of the stream and remove it from the
|
|
|
|
stream. Raise Stream.Failure if the stream is empty. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val empty : 'a t -> unit
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return [()] if the stream is empty, else raise [Stream.Failure]. *)
|
1995-11-10 07:15:12 -08:00
|
|
|
|
|
|
|
|
2001-12-28 15:15:04 -08:00
|
|
|
(** {6 Useful functions} *)
|
2001-10-26 16:33:00 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val peek : 'a t -> 'a option
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return [Some] of "the first element" of the stream, or [None] if
|
|
|
|
the stream is empty. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val junk : 'a t -> unit
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Remove the first element of the stream, possibly unfreezing
|
|
|
|
it before. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val count : 'a t -> int
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return the current count of the stream elements, i.e. the number
|
|
|
|
of the stream elements discarded. *)
|
1995-11-10 07:15:12 -08:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val npeek : int -> 'a t -> 'a list
|
2001-10-26 16:33:00 -07:00
|
|
|
(** [npeek n] returns the list of the [n] first elements of
|
|
|
|
the stream, or all its remaining elements if less than [n]
|
|
|
|
elements are available. *)
|
1997-06-16 08:33:44 -07:00
|
|
|
|
2001-10-30 08:52:04 -08:00
|
|
|
(**/**)
|
1995-11-09 03:04:31 -08:00
|
|
|
|
2012-03-14 09:03:15 -07:00
|
|
|
(* The following is for system use only. Do not call directly. *)
|
1995-11-09 03:04:31 -08:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val iapp : 'a t -> 'a t -> 'a t
|
|
|
|
val icons : 'a -> 'a t -> 'a t
|
|
|
|
val ising : 'a -> 'a t
|
1997-06-16 08:33:44 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val lapp : (unit -> 'a t) -> 'a t -> 'a t
|
|
|
|
val lcons : (unit -> 'a) -> 'a t -> 'a t
|
|
|
|
val lsing : (unit -> 'a) -> 'a t
|
1997-06-16 08:33:44 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val sempty : 'a t
|
|
|
|
val slazy : (unit -> 'a t) -> 'a t
|
1997-06-16 08:33:44 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val dump : ('a -> unit) -> 'a t -> unit
|