[MLton] Parsing bug?

Wesley W. Terpstra terpstra@gkec.tu-darmstadt.de
Mon, 6 Dec 2004 05:13:26 +0100


--xgyAXRrhYN0wYx8y
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

SML/NJ and MLton should give the same output for an SML 97 program running
over the same input, right?  Well, I have a counter-example. =)

As far as I can see, the SML/NJ version gets it right. MLton doesn't.
Even more disturbingly, MLton seems sensitive to how the input file is fed.

If you run './train < train.input' you will get no output.
If you run './train' and cut-and-paste in the input, you get:
"klj"
(5, 7)

... ie: it ignores the first line.

Am I mistaken, or is this a bug?

This behaviour is the same under:
20040227-1
20041109-1
cvs/HEAD

-- 
Wesley W. Terpstra

--xgyAXRrhYN0wYx8y
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="train.input"

5 kljlkj 6 7 ljj
klj 5 7

--xgyAXRrhYN0wYx8y
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="train.output.ok"

"5"
"kljlkj"
(6, 7)
"ljj"
"klj"
(5, 7)

--xgyAXRrhYN0wYx8y
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="train.sml"

fun scanPair cvt scan state =
  case cvt scan state  of NONE => NONE | SOME (v1, state') =>
  case cvt scan state' of NONE => NONE | SOME (v2, state'') =>
  SOME ((v1, v2), state'')

fun scanWord scan state =
  case (StringCvt.splitl (not o Char.isSpace) scan (StringCvt.skipWS scan state)) of
    ("", s) => NONE | (x, s) => SOME (x, s)

val scanInts = TextIO.scanStream (scanPair (Int.scan StringCvt.DEC))
val scanWord = TextIO.scanStream scanWord
val stdIn = TextIO.stdIn

fun showInts x y = print ("(" ^ Int.toString x ^ ", " ^ Int.toString y ^ ")\n")
fun showWord x = print ("\"" ^ x ^ "\"\n")

val done = ref false
val _ = while not (!done) do
  case scanInts stdIn of SOME (x, y) =>  showInts x y | NONE =>
  case scanWord stdIn of SOME x => showWord x | NONE =>
  done := true

--xgyAXRrhYN0wYx8y--