[MLton-commit] r6325

Vesa Karvonen vesak at mlton.org
Mon Jan 14 16:09:16 PST 2008


Enhanced generic read to also skip (* comments *).

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

U   mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml
U   mltonlib/trunk/com/ssh/generic/unstable/test/read.sml

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

Modified: mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml	2008-01-13 20:38:59 UTC (rev 6324)
+++ mltonlib/trunk/com/ssh/generic/unstable/detail/value/read.sml	2008-01-15 00:09:15 UTC (rev 6325)
@@ -241,13 +241,18 @@
       lp 0
    end
 
-   val spaces = drop Char.isSpace
+   fun ignored 0 = drop Char.isSpace >> (L"(*" >> eta ignored 1 <|> return ())
+     | ignored n = L"*)" >> eta ignored (n-1) <|>
+                   L"(*" >> eta ignored (n+1) <|>
+                   elem  >> eta ignored n
 
-   fun l >>> r = l >> spaces >> r
+   val ignored = ignored 0
 
+   fun l >>> r = l >> ignored >> r
+
    fun parens p =
        guess (L"(" >>> eta parens p) >>= (fn x => L")" >>> return x) <|> p
-   fun wrap p = parens (p >>= (fn x => spaces >> return x))
+   fun wrap p = parens (p >>= (fn x => ignored >> return x))
 
    datatype radix = datatype StringCvt.radix
 
@@ -326,7 +331,7 @@
            case Univ.Iso.new ()
             of (to, from) =>
                Sum.map (from, id)
-                       (parse (spaces >> pA)
+                       (parse (ignored >> pA)
                               ((Reader.mapState (from, to) rC, to s),
                                ()))
 
@@ -388,7 +393,7 @@
                     | SOME (i, (_, p)) =>
                       if isSome (Array.sub (a, i))
                       then zero
-                      else spaces >> I"=" >>> p >>= (fn x =>
+                      else ignored >> I"=" >>> p >>= (fn x =>
                            (Array.update (a, i, SOME x)
                           ; if n <= 1
                             then lp a 0
@@ -402,8 +407,8 @@
            of SOME l => SOME (map INL l)
             | NONE   => Option.map (map INR) (r s)
       val unit = L"(" >>> wrap (L")")
-      fun C0 c = C c spaces
-      fun C1 c t = C c (spaces >> t)
+      fun C0 c = C c ignored
+      fun C1 c t = C c (ignored >> t)
       fun data t =
           parens (longId >>= (fn s => case t (String.concatWith "." s)
                                        of NONE   => zero

Modified: mltonlib/trunk/com/ssh/generic/unstable/test/read.sml
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/test/read.sml	2008-01-13 20:38:59 UTC (rev 6324)
+++ mltonlib/trunk/com/ssh/generic/unstable/test/read.sml	2008-01-15 00:09:15 UTC (rev 6325)
@@ -43,7 +43,9 @@
                  p x >>= (fn (a, d) =>
                  return (if Word.isOdd (hash t x)
                          then (a, d)
-                         else (Fixity.ATOMIC, txt " ( " <^> d <^> txt " ) "))))
+                         else (Fixity.ATOMIC,
+                               txt " (* (*:-)*) *) ( (* :-( *) " <^> d <^>
+                               txt " (*) *) ) (* foo *) "))))
              t
    end
 




More information about the MLton-commit mailing list