1 (* Copyright (C
) 1999-2006 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
4 * MLton is released under a BSD
-style license
.
5 * See the file MLton
-LICENSE for details
.
11 structure String = String0
12 structure Char = String.Char
13 structure I
= Pervasive
.TextIO
20 val inputChar
= input1
21 val peekChar
= lookahead
22 val endOf
= endOfStream
24 fun foldChars (ins
, a
, f
) =
29 | SOME l
=> loop (String.fold (l
, a
, f
))
34 fun foldLines (ins
, ac
, f
) =
39 | SOME l
=> loop (f (l
, ac
))
43 fun foreachLine (ins
, f
) = foldLines (ins
, (), f
o #
1)
45 fun inputTo (i
: t
, p
: char
-> bool): string =
47 val maxListLength
= 1000
48 fun finish chars
= String.rev (String.implode chars
)
49 fun loop (n
, chars
, strings
) =
51 NONE
=> (chars
, strings
)
57 val chars
= c
:: chars
61 then loop (n
- 1, chars
, strings
)
62 else loop (maxListLength
,
64 finish chars
:: strings
)
66 val (chars
, strings
) = loop (maxListLength
, [], [])
68 concat (rev (finish chars
:: strings
))
71 fun sameContents (in1
, in2
) =
74 case (input1 in1
, input1 in2
) of
76 |
(SOME c1
, SOME c2
) => Char.equals (c1
, c2
) andalso loop ()
81 fun inputToSpace i
= inputTo (i
, Char.isSpace
)
82 fun inputToChar (i
, c
) = inputTo (i
, fn c
' => Char.equals (c
, c
'))
83 fun ignoreSpaces i
= ignore (inputTo (i
,not
o Char.isSpace
))
85 fun inputNothing _
= ()
87 fun layout _
= Layout
.str
"<instream>"
89 (*val set
= MLton
.TextIO.setIn
*)
93 structure In0
= Instream0