The RegExpFn functor glues together a front-end regular-expression
parser with a back-end regular-expression engine.
Synopsis
signature REGEXP
functor RegExpFn (
structure P : REGEXP_PARSER
structure E : REGEXP_ENGINE
) :> REGEXP where type regexp = E.regexp
Functor Argument Interface
structure P : REGEXP_PARSER
structure E : REGEXP_ENGINE
Functor Argument Description
structure P : REGEXP_PARSER-
The front-end parser for the regular-expression syntax.
structure E : REGEXP_ENGINE-
The back-end engine.
Interface
type regexp
type 'a match = {pos : 'a, len : int} MatchTree.match_tree
exception CannotParse
val compile : (char,'a) StringCvt.reader -> (regexp, 'a) StringCvt.reader
val compileString : string -> regexp
val find : regexp -> (char,'a) StringCvt.reader -> ('a match, 'a) StringCvt.reader
val prefix : regexp -> (char,'a) StringCvt.reader -> ('a match, 'a) StringCvt.reader
val match : (string * ('a match -> 'b)) list
-> (char,'a) StringCvt.reader -> ('b, 'a) StringCvt.reader
Interface Description
type regexp-
The type of a compiled regular expression.
(* a match specifies the position (as a stream) and the length of the match *)
type 'a match = {pos : 'a, len : int} MatchTree.match_tree-
A match tree specifying the starting position and size of matches. For a general character reader
getc, we can extract the string for a match using the following function:fun getMatchString {pos, len} = let fun get (_, 0, chrs) = String.implodeRev chrs | get (strm, n, chrs) = let val SOME(c, rest) = getc strm in get (rest, n-1, c::chrs) end in get (pos, len, []) endMore direct means are possible for specific input sources (e.g., strings, substrings, or text input).
exception CannotParse-
This exception is raised by the functions
compileStringmatchwhen the front-end encounters a syntax error. val compile : (char,'a) StringCvt.reader -> (regexp, 'a) StringCvt.reader-
compile getc strmparses and compiles a regular expression from the input streamstrmusing the character readergetc. If successful, it returnsSOME(re, strm'), wherereis the compiled regular expression andstrm'is the residual input stream. It returnsNONEif there is a syntax error in the input. If the source regular expression contains features that are not supported by the back-end engine, then theCannotCompileexception is raised.
val compileString : string -> regexp-
compileString sreturns the compiled regular expression defined by the strings. TheCannotParseexception is raised if there was a syntax error when parsingsand theCannotCompileexception is raised if the source regular expression contains features that are not supported by the back-end engine. val find : regexp -> (char,'a) StringCvt.reader -> ('a match, 'a) StringCvt.reader-
find re getc strmreturnsSOME mtwheremtdescribes the first match ofrein the input stream; otherwise it returnsNONEif there is no match. val prefix : regexp -> (char,'a) StringCvt.reader -> ('a match, 'a) StringCvt.reader-
prefix re getc strmreturnsSOME mtwheremtdescribes the matching ofreat the beginning of the input stream; otherwise it returnsNONEifredoes not match a prefix of the input.
val match : (string * ('a match -> 'b)) list -> (char,'a) StringCvt.reader -> ('b, 'a) StringCvt.reader-
match rules getc strmattempts to match one of therulesstarting at the current stream position. Each rule is a pair of a regular expression and an action. The rules are tested in order; if a rule(re, act)matches with the resultmt, then the result ofmatchwill beSOME(act mt). If no rule matches, thenNONEis the result.