The MatchTree structure provides a tree-structured representation
of the result of a successful regular expression match. The tree structure
corresponds to the nesting of groups
in the regular expression.
Synopsis
signature MATCH_TREE
structure MatchTree : MATCH_TREE
Interface
datatype 'a match_tree = Match of 'a * 'a match_tree list
val root : 'a match_tree -> 'a
val nth : ('a match_tree * int) -> 'a (* raises Subscript *)
val map : ('a -> 'b) -> 'a match_tree -> 'b match_tree
val app : ('a -> unit) -> 'a match_tree -> unit
val foldl : ('a * 'b -> 'b) -> 'b -> 'a match_tree -> 'b
val foldr : ('a * 'b -> 'b) -> 'b -> 'a match_tree -> 'b
val find : ('a -> bool) -> 'a match_tree -> 'a option
val num : 'a match_tree -> int
Description
datatype 'a match_tree = Match of 'a * 'a match_tree list-
The representation of the results of a nested grouping of regular expressions. The type variable
'ais typically instantiated to information about the particular range of the source that the node covers. For example, it might be the pair of the start position and length of the match. val root : 'a match_tree -> 'a-
root mtreturns the information about the root (outermost) match in the tree. val nth : ('a match_tree * int) -> 'a (* raises Subscript *)-
nth (mt, i)returns the information about thei'th match in the tree, where matches are labeled in pre-order starting with0for the root. This function raises theSubscriptexception ifi < 0or there are fewer thani-1nodes in the tree. val map : ('a -> 'b) -> 'a match_tree -> 'b match_tree-
map f mtreturns the result of mapping the functionfovermt. For example, this function can be used to convert a match-tree of position information to a tree of strings. The function is applied to the tree in pre-order. val app : ('a -> unit) -> 'a match_tree -> unit-
app f mtapplies the given function to the nodes in the tree in pre-order. val foldl : ('a * 'b -> 'b) -> 'b -> 'a match_tree -> 'b-
foldl f init mtfolds the functionfovermtin left-to-right pre-order usinginitas the initial value. val foldr : ('a * 'b -> 'b) -> 'b -> 'a match_tree -> 'b-
foldr f init mtfolds the functionfovermtin right-to-left post-order usinginitas the initial value. val find : ('a -> bool) -> 'a match_tree -> 'a option-
find pred mtreturnsSOME infowhereinfois the first information that satisfiespredin a pre-order traversal of the tree. It returnsNONEif there is no match information that satisfiespred. val num : 'a match_tree -> int-
num mtreturns the number of sub-matches in the tree; i.e., the number of nodes not counting the root.