next up previous contents
Next: Equality tests Up: Pattern match predicates Previous: Pattern match predicates

   
Patterns

In pattern match statements or in predicates of rule tests patterns may appear.


\begin{verbsyntax}\synrule{Pattern}{NodeType}
\lastcont{\vert NodeType '\{' Inne...
...] Pattern}
\lastcont{\vert FieldName ('=>'\vert'==') Variable }
\end{verbsyntax}

Variables in patterns are arbitrary identifiers. There are two kinds of patterns: outer patterns are allowed in pattern match statements, where they match already defined variables. They are also allowed in left or right parameters of simple predicates, however, only at the outer level.

Inner patterns are allowed to occur only in an outer pattern or another inner pattern. They perform field pattern matching and also variable assignment. Positional pattern matching is not possible, only matching with a field name is allowed. Variable assignment assigns a variable to the field, if the pattern match was successful. If no variable assignment is given, assigns a temporary variable to the successfully matched subtree.

For instance, the pattern match

  
S ~ If(Then => A := Assign)

tests whether a variable S consists of a If where the field Then is a Assign. The variable A is assigned to the assignment statement.

As outer patterns, inner patterns test features of nodes and scalars, resulting in testing edges in the rule test graph. Inner patterns differ from outer patterns in so far that the field names in inner patterns are always prefixed by the designation path of the enclosing patterns. This means that all designators are collected from out to inside of the pattern and prefix a field name. For instance, the nested pattern above can be resolved to testing edges as follows, resolving the field pattern match on Then to a designator S.Then:

  
matches(S,If), matches(S.Then,Assign), A := S.Then

Restriction of the current implementation: It is not allowed to use constant patterns. Constant comparisons are only allowed in equality tests (section 3.6.3).


next up previous contents
Next: Equality tests Up: Pattern match predicates Previous: Pattern match predicates
Uwe Assmann
1998-12-22