home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / Bool.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  871 b   |  36 lines  |  [TEXT/R*ch]

  1. (* Bool -- new basis 1995-03-30 *)
  2.  
  3. type bool = bool
  4.  
  5. val not = not;
  6.  
  7. fun toString false = "false"
  8.   | toString true  = "true";
  9.  
  10. fun getstring str getc source =
  11.     let prim_val sub_ : string -> int -> char = 2 "get_nth_char";
  12.     val len = size str
  13.     fun toLower c = 
  14.         if #"A" <= c andalso c <= #"Z" then Char.chr (Char.ord c + 32)
  15.         else c;
  16.     fun h i src = 
  17.         if i >= len then SOME src 
  18.         else case getc src of
  19.         NONE          => NONE
  20.           | SOME(c, rest) => if toLower c = sub_ str i then h (i+1) rest
  21.                  else NONE
  22.     in h 0 source end
  23.  
  24. fun scan getc source =
  25.     let val src = StringCvt.dropl Char.isSpace getc source 
  26.     in
  27.     case getstring "true" getc src of
  28.         SOME rest => SOME(true, rest)
  29.       | NONE  => 
  30.     case getstring "false" getc src of
  31.         SOME rest => SOME(false, rest)
  32.       | NONE => NONE
  33.     end
  34.  
  35. val fromString = StringCvt.scanString scan;
  36.