18 val filter: ('a -> bool) -> ('a, 'b) source -> ('a, ('a, 'b) source) source |
18 val filter: ('a -> bool) -> ('a, 'b) source -> ('a, ('a, 'b) source) source |
19 val of_list: 'a list -> ('a, 'a list) source |
19 val of_list: 'a list -> ('a, 'a list) source |
20 val of_string: string -> (string, string list) source |
20 val of_string: string -> (string, string list) source |
21 val exhausted: ('a, 'b) source -> ('a, 'a list) source |
21 val exhausted: ('a, 'b) source -> ('a, 'a list) source |
22 val of_stream: TextIO.instream -> TextIO.outstream -> (string, unit) source |
22 val of_stream: TextIO.instream -> TextIO.outstream -> (string, unit) source |
|
23 val of_instream_slurp: TextIO.instream -> (string, unit) source |
23 val tty: (string, unit) source |
24 val tty: (string, unit) source |
24 val source': 'a -> 'b * ('b -> bool) -> ('a * 'b list -> 'c list * ('a * 'b list)) -> |
25 val source': 'a -> 'b * ('b -> bool) -> ('a * 'b list -> 'c list * ('a * 'b list)) -> |
25 ('a * 'b list -> 'c list * ('a * 'b list)) option -> |
26 ('a * 'b list -> 'c list * ('a * 'b list)) option -> |
26 ('b, 'e) source -> ('c, 'a * ('b, 'e) source) source |
27 ('b, 'e) source -> ('c, 'a * ('b, 'e) source) source |
27 val source: 'a * ('a -> bool) -> ('a list -> 'b list * 'a list) -> |
28 val source: 'a * ('a -> bool) -> ('a list -> 'b list * 'a list) -> |
118 make_source [] () default_prompt (drain_stream instream outstream); |
119 make_source [] () default_prompt (drain_stream instream outstream); |
119 |
120 |
120 val tty = of_stream TextIO.stdIn TextIO.stdOut; |
121 val tty = of_stream TextIO.stdIn TextIO.stdOut; |
121 |
122 |
122 |
123 |
|
124 (* no prompt output, slurp input eagerly *) |
|
125 (* NB: if canInput isn't supported, falls back to line input *) |
|
126 |
|
127 fun drain_stream' instream _ () = |
|
128 let fun lines xs = |
|
129 (case TextIO.canInput (instream, 1) of |
|
130 NONE => xs |
|
131 | SOME 0 => ""::xs (* EOF *) |
|
132 | SOME _ => lines ((TextIO.inputLine instream) :: xs)) |
|
133 handle Io => xs |
|
134 in (flat (map explode (rev (lines [TextIO.inputLine instream]))), ()) end; |
|
135 |
|
136 fun of_instream_slurp instream = |
|
137 make_source [] () default_prompt (drain_stream' instream); |
|
138 |
123 |
139 |
124 (** compose sources **) |
140 (** compose sources **) |
125 |
141 |
126 fun drain_source source stopper scan recover prompt src = |
142 fun drain_source source stopper scan recover prompt src = |
127 source prompt get_prompt unget stopper scan recover src; |
143 source prompt get_prompt unget stopper scan recover src; |