MLton / mlton

The MLton repository
http://mlton.org
Other
962 stars 127 forks source link

Word.scan #494

Closed minoki closed 1 year ago

minoki commented 1 year ago

MLton's Word.scan seems to be buggy when 0 is followed by w/x but not by more digits.

Example:

fun testScan scan s = case scan Substring.getc (Substring.full s) of
                          NONE => print "NONE\n"
                        | SOME (result, rest) => print ("SOME (0w" ^ Word.fmt StringCvt.DEC result ^ ", \"" ^ Substring.string rest ^ "\")\n")
val () = List.app (testScan (Word.scan StringCvt.BIN))
                  ["0", "0w", "0wx", "0x"];
val () = List.app (testScan (Word.scan StringCvt.OCT))
                  ["0", "0w", "0wx", "0x"];
val () = List.app (testScan (Word.scan StringCvt.DEC))
                  ["0", "0w", "0wx", "0x"];
val () = List.app (testScan (Word.scan StringCvt.HEX))
                  ["0", "0w", "0wx", "0x"];

Expected output:

SOME (0w0, "")
SOME (0w0, "w")
SOME (0w0, "wx")
SOME (0w0, "x")
SOME (0w0, "")
SOME (0w0, "w")
SOME (0w0, "wx")
SOME (0w0, "x")
SOME (0w0, "")
SOME (0w0, "w")
SOME (0w0, "wx")
SOME (0w0, "x")
SOME (0w0, "")
SOME (0w0, "w")
SOME (0w0, "wx")
SOME (0w0, "x")

MLton's output:

SOME (0w0, "")
SOME (0w0, "")
SOME (0w0, "x")
NONE
SOME (0w0, "")
SOME (0w0, "")
SOME (0w0, "x")
NONE
SOME (0w0, "")
SOME (0w0, "")
SOME (0w0, "x")
NONE
SOME (0w0, "")
SOME (0w0, "w")
SOME (0w0, "")
SOME (0w0, "")
MatthewFluet commented 1 year ago

Agreed, this is deviating from the SML Basis Library specification. Should be easy enough to fix.