1open regexpMatch;
2(* /opt/hol_bir/tools/Holmake/regexpMatch.sml *)
3
4structure regexRef :> regex =
5struct
6
7  open regexType;
8
9(*
10  datatype regexp
11    = Epsilon
12    | Symbs of char Binaryset.set
13    | Not of regexp
14    | Sum of regexp * regexp
15    | And of regexp * regexp
16    | Dot of regexp * regexp
17    | Star of regexp
18
19  val empty_cset : char Binaryset.set
20  val univ_cset : char Binaryset.set
21  val pred_to_set : (char -> bool) -> char Binaryset.set
22
23  structure POSIX : sig
24    val alnum_set  : char Binaryset.set
25    val alpha_set  : char Binaryset.set
26    val ascii_set  : char Binaryset.set
27    val blank_set  : char Binaryset.set
28    val cntrl_set  : char Binaryset.set
29    val digit_set  : char Binaryset.set
30    val graph_set  : char Binaryset.set
31    val lower_set  : char Binaryset.set
32    val print_set  : char Binaryset.set
33    val punct_set  : char Binaryset.set
34    val space_set  : char Binaryset.set
35    val upper_set  : char Binaryset.set
36    val xdigit_set : char Binaryset.set
37    val word_set   : char Binaryset.set
38  end
39
40  val regexp_compare : regexp * regexp -> order
41  val regexpEqual : regexp -> regexp -> bool
42
43  val regexp_to_dfa_arrays
44      : regexp -> {delta : int vector vector,
45                   start : int,
46                   final : bool vector}
47
48  val match : regexp -> string -> bool
49
50*)
51
52
53
54  fun mapToRegRef r =
55        case r of
56            Eps        => regexpMatch.Epsilon
57          | Sym c      => regexpMatch.Symbs (pred_to_set (fn x => x = c))
58          | Alt (p, q) => regexpMatch.Sum (mapToRegRef p, mapToRegRef q)
59          | Seq (p, q) => regexpMatch.Dot (mapToRegRef p, mapToRegRef q)
60          | Rep r      => regexpMatch.Star (mapToRegRef r)
61
62
63  fun match (r:Reg) (s:string) = regexpMatch.match (mapToRegRef r) s;
64
65
66end
67