home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Bool.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  850 b   |  34 lines  |  [TEXT/R*ch]

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