[MLton-commit] r7004

Vesa Karvonen vesak at mlton.org
Tue Dec 16 02:21:31 PST 2008


Added ad-hoc tests for sepEndBy and sepEndBy1 and fixed a bug in
sepEndBy1.

----------------------------------------------------------------------

U   mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun
U   mltonlib/trunk/org/mlton/vesak/parsec/unstable/test/parsec.sml

----------------------------------------------------------------------

Modified: mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun
===================================================================
--- mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun	2008-12-14 22:46:44 UTC (rev 7003)
+++ mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun	2008-12-16 10:21:30 UTC (rev 7004)
@@ -195,14 +195,16 @@
    fun sepBy1 p s = oneMany p (s ->> p)
    fun sepBy p s = sepBy1 p s <|> return []
 
-   fun sepEndBy p s = let
+   fun sepEndBy' p s = let
       fun done xs ? = return (rev xs) ?
       fun pee xs = p >>= (fn x => ess (x::xs)) <|> done xs
       and ess xs = s >>= (fn _ => pee xs) <|> done xs
    in
-      pee []
+      pee
    end
 
+   fun sepEndBy p s = sepEndBy' p s []
+
    fun sepEndBy1 p s =
-       p >>= (fn x => s >>= (fn _ => map (fn xs => x::xs) (sepEndBy p s)))
+       p >>= (fn x => s >>= (fn _ => sepEndBy' p s [x]) <|> return [x])
 end

Modified: mltonlib/trunk/org/mlton/vesak/parsec/unstable/test/parsec.sml
===================================================================
--- mltonlib/trunk/org/mlton/vesak/parsec/unstable/test/parsec.sml	2008-12-14 22:46:44 UTC (rev 7003)
+++ mltonlib/trunk/org/mlton/vesak/parsec/unstable/test/parsec.sml	2008-12-16 10:21:30 UTC (rev 7004)
@@ -84,5 +84,10 @@
     (chk (sepBy1 l u |>> implode) String.t
          [F "-" 0, S "aXb-" "ab" "-", F "aXbY" 4])
 
+    (chk (sepEndBy l u |>> implode) String.t
+         [S"x-""x""-", S"xA-""x""-", S"aXb-""ab""-", S"bXaY-""ba""-"])
+    (chk (sepEndBy1 l u |>> implode) String.t
+         [S"x-""x""-", S"xA-""x""-", S"aXb-""ab""-", S"bXaY-""ba""-", F"-"0])
+
     $
 end




More information about the MLton-commit mailing list