[MLton-commit] r6632

Vesa Karvonen vesak at mlton.org
Fri May 30 06:27:38 PDT 2008


Added some basic parsing combinators.  Renamed ^* to many (as in Parsec).
----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml
U   mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun
U   mltonlib/trunk/org/mlton/vesak/parsec/unstable/public/parsec.sig

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

Modified: mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml	2008-05-30 13:13:59 UTC (rev 6631)
+++ mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml	2008-05-30 13:27:37 UTC (rev 6632)
@@ -78,7 +78,7 @@
    val symbolicId = id isSymbolic isSymbolic
 
    val shortId = alphaId <|> symbolicId
-   val longId = map op :: (shortId >>* ^* (E#"." >> shortId))
+   val longId = map op :: (shortId >>* many (E#"." >> shortId))
    fun I s = shortId >>= (fn i => if i = s then return () else zero)
 
    val numLabel = id (Char.inRange (#"1", #"9")) Char.isDigit

Modified: mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun
===================================================================
--- mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun	2008-05-30 13:13:59 UTC (rev 6631)
+++ mltonlib/trunk/org/mlton/vesak/parsec/unstable/detail/mk-parsec.fun	2008-05-30 13:27:37 UTC (rev 6632)
@@ -142,8 +142,21 @@
                                     of OK (x, _, m) => taste (OK (x, s, m))
                                      | FAIL m       => taste (FAIL m)
 
-   fun ^* p = p >>= (fn x => ^* p >>= (fn xs => return (x::xs))) <|> return []
+   fun many p = many1 p <|> return []
+   and many1 p = p >>= (fn x => many p >>= (fn xs => return (x::xs)))
 
+   fun between b a p = b >>= (fn _ => p >>= (fn r => a >>= (fn _ => return r)))
+
+   fun option alt p = p <|> return alt
+
+   fun sepBy1 p s =
+       p >>= (fn x => many (s >>= (fn _ => p)) >>= (fn xs => return (x::xs)))
+   fun sepBy p s = sepBy1 p s <|> return []
+
+   fun skip p = p >>= return o ignore
+   fun skipMany p = skipMany1 p <|> return ()
+   and skipMany1 p = p >>= (fn _ => skipMany p)
+
    structure Monad = MkMonadP
      (type 'a monad = 'a t
       val return = return

Modified: mltonlib/trunk/org/mlton/vesak/parsec/unstable/public/parsec.sig
===================================================================
--- mltonlib/trunk/org/mlton/vesak/parsec/unstable/public/parsec.sig	2008-05-30 13:13:59 UTC (rev 6631)
+++ mltonlib/trunk/org/mlton/vesak/parsec/unstable/public/parsec.sig	2008-05-30 13:27:37 UTC (rev 6632)
@@ -35,5 +35,18 @@
    val take : Sequence.Elem.t UnPr.t -> Sequence.Elem.t List.t t
 
    val peek : 'a t UnOp.t
-   val ^* : 'a t -> 'a List.t t
+
+   val many : 'a t -> 'a List.t t
+   val many1 : 'a t -> 'a List.t t
+
+   val option : 'a -> 'a t UnOp.t
+
+   val between : 'a t -> 'b t -> 'c t UnOp.t
+
+   val sepBy : 'a t -> 'b t -> 'a List.t t
+   val sepBy1 : 'a t -> 'b t -> 'a List.t t
+
+   val skip : 'a t -> Unit.t t
+   val skipMany : 'a t -> Unit.t t
+   val skipMany1 : 'a t -> Unit.t t
 end




More information about the MLton-commit mailing list