| 1 | (**************************************************************************) |
| 2 | (* *) |
| 3 | (* OCaml *) |
| 4 | (* *) |
| 5 | (* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) |
| 6 | (* *) |
| 7 | (* Copyright 1997 Institut National de Recherche en Informatique et *) |
| 8 | (* en Automatique. *) |
| 9 | (* *) |
| 10 | (* All rights reserved. This file is distributed under the terms of *) |
| 11 | (* the GNU Lesser General Public License version 2.1, with the *) |
| 12 | (* special exception on linking described in the file LICENSE. *) |
| 13 | (* *) |
| 14 | (**************************************************************************) |
| 15 | |
| 16 | (** Streams and parsers. *) |
| 17 | |
| 18 | type ('e,'a) t |
| 19 | (** The type of streams holding values of type ['a]. |
| 20 | Producing a new value needs an environment ['e]. *) |
| 21 | |
| 22 | (** {1 Stream builders} *) |
| 23 | |
| 24 | val from : ?offset:int -> ('e -> 'a option) -> ('e,'a) t |
| 25 | (** [Stream.from f] returns a stream built from the function [f]. To |
| 26 | create a new stream element, the function [f] is called. The user |
| 27 | function [f] must return either [Some <value>] for a value or |
| 28 | [None] to specify the end of the stream. [offset] will initialize |
| 29 | the stream [count] to start with [offset] consumed items, which is |
| 30 | useful for some uses cases such as parsing resumption. |
| 31 | *) |
| 32 | |
| 33 | val empty : unit -> ('e,'a) t |
| 34 | (** Return the stream holding the elements of the list in the same |
| 35 | order. *) |
| 36 | |
| 37 | val of_string : ?offset:int -> string -> (unit,char) t |
| 38 | (** Return the stream of the characters of the string parameter. If |
| 39 | set. [offset] parameter is similar to [from]. *) |
| 40 | |
| 41 | val of_channel : in_channel -> (unit,char) t |
| 42 | (** Return the stream of the characters read from the input channel. *) |
| 43 | |
| 44 | (** {1 Predefined parsers} *) |
| 45 | |
| 46 | val next : 'e -> ('e,'a) t -> 'a option |
| 47 | (** Return the first element of the stream and remove it from the |
| 48 | stream. [None] if the stream is empty. *) |
| 49 | |
| 50 | val is_empty : 'e -> ('e,'a) t -> bool |
| 51 | (** Return [true] if the stream is empty, else [false]. *) |
| 52 | |
| 53 | |
| 54 | (** {1 Useful functions} *) |
| 55 | |
| 56 | val peek : 'e -> ('e,'a) t -> 'a option |
| 57 | (** Return [Some] of "the first element" of the stream, or [None] if |
| 58 | the stream is empty. *) |
| 59 | |
| 60 | val junk : 'e -> ('e,'a) t -> unit |
| 61 | (** Remove the first element of the stream, possibly unfreezing |
| 62 | it before. *) |
| 63 | |
| 64 | val count : ('e,'a) t -> int |
| 65 | (** Return the current count of the stream elements, i.e. the number |
| 66 | of the stream elements discarded. *) |
| 67 | |
| 68 | val npeek : 'e -> int -> ('e,'a) t -> 'a list |
| 69 | (** [npeek e n] returns the list of the [n] first elements of |
| 70 | the stream, or all its remaining elements if less than [n] |
| 71 | elements are available. *) |
| 72 | |
| 73 | val nth : 'e -> int -> ('e,'a) t -> 'a option |
| 74 | (** Returns the [n]th (0-indexed) element of the sream without |
| 75 | consuming, or [None] if less than [n+1] elements are available. *) |
| 76 | |
| 77 | val njunk : 'e -> int -> ('e,'a) t -> unit |
| 78 | |
| 79 | (**/**) |