home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / lib / stream.mli < prev    next >
Encoding:
Text File  |  1993-09-24  |  2.1 KB  |  57 lines  |  [TEXT/MPS ]

  1. (* Operations on streams *)
  2.  
  3. #open "io";;
  4.  
  5. type 'a stream;;
  6.  
  7. exception Parse_failure;;
  8.   (* Raised by parsers when none of the first component of the stream patterns
  9.      is accepted *)
  10. exception Parse_error;;
  11.   (* Raised by parsers when the first component of a stream pattern is
  12.      accepted, but one of the following components is rejected *)
  13.  
  14. value stream_next : 'a stream -> 'a;;
  15.   (* [stream_next s] returns the first element of stream [s],
  16.      and removes it from the stream. Raise [Parse_failure] if the
  17.      stream is empty. *)
  18.  
  19. value stream_from : (unit -> 'a) -> 'a stream;;
  20.   (* [stream_from f] returns the stream which fetches its terminals using
  21.      the function [f]. This function could be defined as:
  22. -    [    let rec stream_from f = [< 'f(); stream_from f >]]
  23. -    but is implemented more efficiently. *)
  24.  
  25. value stream_of_string : string -> char stream;;
  26.   (* [stream_of_string s] returns the stream of the characters in
  27.      string [s]. *)
  28.  
  29. value stream_of_channel : in_channel -> char stream;;
  30.   (* [stream_of_channel ic] returns the stream of characters read on
  31.      channel [ic]. *)
  32.  
  33. value do_stream : ('a -> 'b) -> 'a stream -> unit;;
  34.   (* [do_stream f s] scans the whole stream [s], applying the function [f]
  35.      in turn to each terminal encountered *)
  36.  
  37. value stream_check : ('a -> bool) -> 'a stream -> 'a;;
  38.   (* [stream_check p] returns the parser which returns the first terminal of
  39.      the stream if the predicate [p] returns [true] on this terminal,
  40.      and raises [Parse_failure] otherwise. *)
  41.  
  42. value end_of_stream : 'a stream -> unit;;
  43.   (* Return [()] iff the stream is empty, and raise [Parse_failure]
  44.      otherwise.  *)
  45.  
  46. value stream_get : 'a stream -> 'a * 'a stream;;
  47.   (* [stream_get s] return the first element of the stream [s], and a stream
  48.      containing the remaining elements of [s]. Raise [Parse_failure] if the
  49.      stream is empty. The stream [s] is not modified. This function makes it
  50.      possible to access a stream non-destructively. *)
  51.  
  52. (*-- The following functions are for internal use. *)
  53.  
  54. value stream_require : 'a stream -> 'a
  55.   and parser_require : ('a stream -> 'a) -> 'a stream -> 'a
  56. ;;
  57.