-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregular_expr.mli
115 lines (71 loc) · 2.73 KB
/
regular_expr.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
(*
This module defines the regular expressions, and provides some simple
manipulation of them.
\subsection{The regexp datatype and its constructors}
The type of regular expressions is abstract. Regular expressions may
be built from the following constructors :
\begin{itemize}
\item [empty] is the regexp that denotes no word at all.
\item [epsilon] is the regexp that denotes the empty word.
\item [char c] returns a regexp that denotes only the single-character
word [c].
\item [chars s] returns a regexp that denotes any single-character
word belonging to set of chars [s].
\item [string str] denotes the string [str] itself.
\item [star e] where [e] is a regexp, denotes the Kleene iteration of
[e], that is all the words made of concatenation of zero, one or more
words of [e].
\item [alt e1 e2] returns a regexp for the union of languages of [e1]
and [e2].
\item [seq e1 e2] returns a regexp for the concatenation of languages
of [e1] and [e2].
\item [opt e] returns a regexp for the set of words of [e] and the
empty word.
\item [some e] denotes all the words made of concatenation of one or
more words of [e].
\end{itemize}
*)
type regexp;;
val uniq_tag : regexp -> int;;
val empty : regexp;;
val epsilon : regexp;;
val char : char -> regexp;;
val char_interv : char -> char -> regexp;;
val string : string -> regexp;;
val star : regexp -> regexp;;
val alt : regexp -> regexp -> regexp;;
val seq : regexp -> regexp -> regexp;;
val opt : regexp -> regexp;;
val some : regexp -> regexp;;
(*
\subsection{Simple regexp operations}
The following three functions provide some simple operations on
regular expressions:
\begin{itemize}
\item [nullable r] returns [true] if regexp [r] accepts the empty
word.
\item [residual r c] returns the regexp [r'] denoting the language
of words $w$ such that [c]$w$ is in the language of [r].
\item [firstchars r] returns the set of characters that may occur at
the beginning of words in the language of [e].
\end{itemize}
*)
val nullable : regexp -> bool;;
val residual : regexp -> int -> regexp ;;
val firstchars : regexp -> (int * int * regexp) list ;;
(*
\subsection{Regexp matching by runtime interpretation of regexp}
[match_string r s] returns true if the string [s] is in the language
denoted by [r]. This function is by no means efficient, but it is
enough if you just need to match once a simple regexp against a
string.
If you have a complicated regexp, or if you're going to match the
same regexp repeatedly against several strings, we recommend to use
compilation of regexp provided by module [Automata].
*)
val match_string : regexp -> string -> bool;;
(*
pretty-printer
*)
val fprint : Format.formatter -> regexp -> unit;;
val print : regexp -> unit;;