Skip to content

Commit fd6d870

Browse files
authored
Merge pull request #536 from MatthewFluet/imperativeio-getinstream-bug
Fix bug in `ImperativeIO(...).getInstream`
2 parents 15a19ab + 3d19b93 commit fd6d870

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

basis-library/io/imperative-io.fun

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* Copyright (C) 2013,2017 Matthew Fluet.
1+
(* Copyright (C) 2013,2017,2023 Matthew Fluet.
22
* Copyright (C) 2002-2007 Henry Cejtin, Matthew Fluet, Suresh
33
* Jagannathan, and Stephen Weeks.
44
*
@@ -681,7 +681,7 @@ fun getInstream (ib as In {state, ...}) =
681681
AS.vector (AS.slice (buf, f,
682682
SOME (l - f)))))
683683
else doit (false, NONE)
684-
val () = state := Stream s
684+
val () = setInstream (ib, s)
685685
in
686686
s
687687
end

regression/textio.3.ok

Whitespace-only changes.

regression/textio.3.sml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(* See https://github.com/MLton/mlton/issues/535. *)
2+
3+
datatype tree = Leaf of char | Node of tree * tree
4+
5+
fun nextis c cs =
6+
case TextIO.StreamIO.input1 (TextIO.getInstream cs) of
7+
NONE => false
8+
| SOME (c', cs') => c' = c
9+
10+
(* This version works. *)
11+
(*
12+
fun nextis c cs =
13+
case TextIO.lookahead cs of
14+
NONE => false
15+
| SOME c' => c' = c
16+
*)
17+
18+
fun discard c cs =
19+
let val c' = valOf (TextIO.input1 cs) in
20+
if c = c'
21+
then ()
22+
else raise Fail ("unexpected character: " ^ Char.toString c' ^ ", expecting: " ^ Char.toString c)
23+
end
24+
25+
fun parse cs =
26+
case valOf (TextIO.input1 cs) of
27+
#"(" =>
28+
let
29+
fun loop l r =
30+
if nextis #")" cs
31+
then (discard #")" cs; Node (l, r))
32+
else loop (Node (l, r)) (parse cs)
33+
in
34+
loop (parse cs) (parse cs)
35+
end
36+
| c => Leaf c
37+
38+
val cs = TextIO.openString "(a(bc)d)"
39+
40+
(* with this it works too *)
41+
(* val true = nextis #"(" cs *)
42+
43+
val t = (parse cs)

0 commit comments

Comments
 (0)