<\body> Regular expressions naturally generalize from strings to trees and allow to test whether a given tree matches a given pattern. implements the primitives and for this purpose, which also provide support for wildcards, user-defined grammars and more. <\explain> )> <|explain> This function determines whether a scheme expression satisfies a given . It will be detailed below how to form valid patterns. The matching routines recursively understand that native trees match their scheme counterparts. For instance, )> will return (meaning #t> ) and )> will return . <\explain> )> <|explain> Given a list of scheme expressions, a with free variables and an association list of , this routine determines all substitutions of free variables by values (extending the given ), for which matches the . <\explain> )> <|explain> Given a list of rules of the form ... )>, this instruction defines a new terminal symbol > for each such rule, which matches the disjunction of the patterns until . This terminal symbol can then be used as an abbreviation in matching patterns. Grammar rules may be interdependent. See example below. Valid patterns are formed in the following ways: <\explain> <|explain> A is only matched against itself. <\explain> ... )> <|explain> In the case when lists until match until , their concatenation matches the pattern ... )>. <\explain> , , ..., <|explain> The wildcard , where is a number matches any list of length . The wildcard matches any list, including the empty list. <\explain> > <|explain> This pattern attempts to bind the variable against the expression. If is used only once, then it essentially behaves as a wildcard. More generally, it can be used to form patterns with identical subexpressions. For instance, the pattern will match all fractions >. <\explain> > <|explain> In the case when > is a user-provided terminal symbol (see above), this pattern matches the corresponding grammar. <\explain> > predicates> <|explain> Given a predicate , such as , this pattern matches any scheme expression which satisfies the predicate. <\explain> )> ... )> ... )> <|explain> Negation, disjunction and conjunction of patterns. <\explain> )> <|explain> Given lists until which match , their concatenation matches the repetition )>. In particular, the empty list is matched. <\explain> ... )> <|explain> Groups a concatenation of patterns into a new list patterns. For instance, all lists of the form are matched by , whereas rather matches all lists of the form . <\explain> )> <|explain> Only matches a given expression . <\example> The tree <\scm-code> (define t '(foo (bar "x") (bar "y") (option "z"))) matches the pattern , but not . The call will return . <\with|color|red> Actually this gives ``wrong-number-of-args'' but we have: <\session|scheme|default> <\input|Scheme] > (define t '(foo (bar "x") (bar "y") (option "z"))) <\unfolded-io|Scheme] > (match? t '(foo 'x 'y :*)) <|unfolded-io> (((y bar "y") (x bar "x"))) Which has a different format <\example> Consider the grammar <\scm-code> (define-regexp-grammar \ \ (:a a b c) \ \ (:b (:repeat :a))) Then the list matches the pattern . <\session|scheme|default> <\input|Scheme] > (define-regexp-grammar \ \ (:a a b c) \ \ (:b (:repeat :a))) <\unfolded-io|Scheme] > (match? \ '(a b x y c a a) \ (:b :%2 :b)) <|unfolded-io> misc-error <\input|Scheme] > \; <\initial> <\collection>