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

  1. (* Auxiliaries for the parser. *)
  2.  
  3. local
  4.   open List Syntax;
  5. in
  6.  
  7. fun regexp_for_string s =
  8.   let open CharVector infix 9 sub
  9.       val len = length s
  10.       fun re_string n =
  11.         if n >= len then Epsilon
  12.         else if n+1 = len then Characters([s sub n])
  13.         else Sequence(Characters([s sub n]), re_string (n+1))
  14.   in re_string 0 end
  15. ;
  16.  
  17. fun char_class c1 c2 =
  18.   let fun class n =
  19.         if n > Char.ord c2 then
  20.           []
  21.         else
  22.           (Char.chr n) :: class(n+1)
  23.   in class (Char.ord c1) end
  24. ;
  25.  
  26. val all_chars = char_class #"\001" #"\255";
  27.  
  28. fun subtract xs [] = xs
  29.   | subtract xs ys =
  30.       List.filter (fn x => not(Fnlib.member x ys)) xs
  31. ;
  32.  
  33. end;
  34.