SML/NJ Library Manual

The MatchTree structure


signature MATCH_TREE
structure MatchTree : MATCH_TREE

This structure implements the type used to report matching information and associated operations.


datatype 'a match_tree
  = Match of ('a * 'a match_tree list)
val root : 'a match_tree -> 'a
val nth : ('a match_tree * int) -> 'a
val map : ('a -> 'b) -> 'a match_tree -> 'b match_tree
val app : ('a -> unit) -> 'a match_tree -> unit
val find : ('a -> bool) -> 'a match_tree -> 'a option
val num : 'a match_tree -> int


datatype 'a match_tree

root mt
returns the root (outermost) match in the tree mt.

nth (mt, n)
returns the nth match in the tree mt. Matches are labeled in preorder, starting at 0. The nth match in a tree correspond to the match of the nth subexpression of a regular expression, when counted from left to right (and letting the full expression be indexed at 0).

map f mt
maps a function f over the tree mt in preorder.

app f mt
applies a given function f over every element of the tree mt in preorder.

find f mt
finds the first match in the tree mt that satisfies the predicate f (or NONE).

num mt
returns the number of matches included in the tree mt.

[ Top | Parent | Contents | Index | Root ]

Last Modified June 3, 1998
Comments to John Reppy
Copyright © 1998 Bell Labs, Lucent Technologies