2.1.5. Pattern Composition

[Tip]Description

Pattern composition enables the reusability of graph patterns by allowing to combine elementary graph patterns into complex patterns in a declarative way.

Pattern composition can be initiated in the following contexts:

  1. from the body of another GT pattern as part of its pattern body

  2. as part of a negative pattern,

  3. in the precondition of a GT rule definition,

  4. in the postcondition part of a GT rule definition,

[Important]Syntax
PatternCompositionAST ::= find QualifiedTypeNameAST ActualPatternParameterDefAST
ActualPatternParameterDefAST ::= ( ActualParamsPatternVariablesAST ) 
                               | ( ) 

The syntax of pattern composition is formally identical to the syntax of a graph pattern call. However, a main restriction is that only pattern variables may appear as actual parameters in a pattern composition, and not arbitrary terms as in case of graph pattern call.

[Note]Semantics

The semantics of called graph patterns differs on the context in which the pattern call is initiated.

Case 1: Pattern called from another pattern

A graph pattern call (initiated from another pattern or as a precondition pattern of a GT rule definition injects additional structural constraints to caller pattern in the following cases:

Case 2: Pattern called from postcondition of GT rule

When pattern composition is part of the postcondition of a GT rule definition, it defines model manipulation (typically, bulk creation of model elements). This semantics is discussed in GT rule definition, and thus omitted here.

As in case of graph pattern call, the variables in the actual parameter list supplied to the called graph pattern from the caller pattern can be either bound or unbound.

  • If an actual parameter is bound then it is an input parameter for pattern matching. The binding of all input parameters is kept unchanged during pattern matching.

  • If an actual parameter is unbound then it is an output parameter, and a binding is calculated during pattern matching.

In case of pattern composition , each actual parameter is required to be a pattern variable (with respective semantics) instead of arbitrary ASM term as in case of graph pattern calls.

As a general rule (i.e. in case of positive pattern composition), if the matching of a subpattern fails, then the matching of the entire pattern also fails. However, if the subpattern is a negative pattern, then the success of the caller is reversed, i.e. if the subpattern fails, then the caller succeeds, and vice versa.

Pattern composition can also be recursive, i.e. a pattern may call itself as a subpattern in one or more pattern bodies. Recursion is evaluated by bottom-up fixpoint calculation.

It is worth pointing out that a very general interpretation is allowed in VTCL: the only structural restriction is that recursion in positive and negative patterns are not allowed to interfere, i.e. if a pattern is called recursively in a negative pattern, than it is not allowed to be called recursively in the positive pattern, and vice versa. Note that this restriction only applies to recursive pattern composition calls.

See also:  Graph pattern call,