blob: 71cf79e24d325f49bceb67c02c6cb5b21c4ad0d4 [file] [log] [blame]
<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>2.1.2.&nbsp;Pattern Body</title><link href="style.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.72.0" name="generator"><link rel="start" href="index.html" title="The VIATRA2 Model Transformation Framework"><link rel="up" href="sec_PatternDefinition.html" title="2.1.&nbsp;Pattern Definition"><link rel="prev" href="def_GraphPatternDef.html" title="2.1.1.&nbsp;Graph Pattern Definition"><link rel="next" href="def_NegativePattern.html" title="2.1.3.&nbsp;Negative Pattern"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">2.1.2.&nbsp;Pattern Body</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="def_GraphPatternDef.html">Prev</a>&nbsp;</td><th align="center" width="60%">2.1.&nbsp;Pattern Definition</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="def_NegativePattern.html">Next</a></td></tr></table><hr></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="def_PatternBody"></a>2.1.2.&nbsp;Pattern Body</h4></div></div></div><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip: Description"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left"><a name="def_PatternBody_Description"></a>Description</th></tr><tr><td valign="top" align="left"><p>
<span class="strong"><strong>Pattern body</strong></span>
<a name="N1039A" class="indexterm"></a>
is the basic part of the
<a href="def_GraphPatternDef.html" title="2.1.1.&nbsp;Graph Pattern Definition">graph pattern definition</a>.
It determines a constraint set that identifies a part of the model space.
</p></td></tr></table></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important: Syntax"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Important]" src="images/important.png"></td><th align="left"><a name="def_PatternBody_Syntax"></a>Syntax</th></tr><tr><td valign="top" align="left"><pre class="programlisting">
PatternBodiesAST ::= PatternBodyAST
| PatternBodiesAST <span class="token">or</span> PatternBodyAST
PatternBodyAST ::= <span class="token">{</span> PatternBodyContentsAST <span class="token">}</span>
PatternBodyContentsAST ::= $empty
| PatternBodyContentsAST PatternBodyContentDefAST
PatternBodyContentDefAST ::= PatternBodyContentAST <span class="token">;</span>
| <span class="token">neg</span> <a href="def_GraphPatternDef.html" title="2.1.1.&nbsp;Graph Pattern Definition">GraphPatternDefAST</a>
PatternBodyContentAST ::= LocalPatternBodyElementAST
| <a href="def_PatternComposition.html" title="2.1.5.&nbsp;Pattern Composition">PatternCompositionAST</a>
| <a href="def_NegativePattern.html" title="2.1.3.&nbsp;Negative Pattern">NegativePatternAST</a>
| <a href="def_PatternVariableAssignment.html" title="2.1.7.&nbsp;Pattern Variable Assignment">PatternVariableAssignmentAST</a>
| <a href="def_CheckCondition.html" title="2.1.8.&nbsp;Check Condition">CheckConditionAST</a>
LocalPatternBodyElementAST ::= ModelElementAST | <a href="def_Relationship.html" title="2.2.3.&nbsp;Relationships">RelationshipAST</a>
ModelElementAST ::= <a href="def_Entity.html" title="2.2.1.&nbsp;Entity">EntityAST</a>| <a href="def_Relation.html" title="2.2.2.&nbsp;Relation">RelationAST</a>
</pre><p>
A <span class="strong"><strong>pattern body</strong></span>
<a name="N103DF" class="indexterm"></a>
mainly consists of <span class="strong"><strong>local pattern body elements</strong></span>
<a name="N103E8" class="indexterm"></a>. These defines the typed structure of the pattern. A
<span class="strong"><strong>local pattern body element</strong></span>
can be either a
<span class="strong"><strong>model element</strong></span>
<a name="N103F5" class="indexterm"></a>
or a
<a href="def_Relationship.html" title="2.2.3.&nbsp;Relationships">relationship</a>
definition between model elements. A
<span class="strong"><strong>model element</strong></span>
is either an
<a href="def_Entity.html" title="2.2.1.&nbsp;Entity">entity</a>
or a
<a href="def_Relation.html" title="2.2.2.&nbsp;Relation">relation</a>.
<span class="strong"><strong>Model element</strong></span>
<a name="N1040E" class="indexterm"></a>
are identified by <a href="def_PatternVariable.html" title="2.1.6.&nbsp;Pattern Variable">pattern variables</a>:
these are either the parameters of the pattern or internal variables.
</p><p>
From a
<span class="strong"><strong>pattern body</strong></span>
<a name="N1041D" class="indexterm"></a>, another graph pattern can be invoked by
<a href="def_PatternComposition.html" title="2.1.5.&nbsp;Pattern Composition">pattern composition</a>
or as a
<a href="def_NegativePattern.html" title="2.1.3.&nbsp;Negative Pattern">negative pattern</a>.
</p><p>
Within a
<span class="strong"><strong>pattern body</strong></span>
the unification of variables can be defined: it is called
<a href="def_PatternVariableAssignment.html" title="2.1.7.&nbsp;Pattern Variable Assignment">pattern variable assignment</a>.
</p><p>
Extra conditions can be states in addition to those that defines the typed structure. These are called
<a href="def_CheckCondition.html" title="2.1.8.&nbsp;Check Condition">check condition</a>
s and are formulated by ASM terms.
</p></td></tr></table></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note: Semantics"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left"><a name="def_PatternBody_Semantics"></a>Semantics</th></tr><tr><td valign="top" align="left"><p>
A pattern body defines a conjunction of constraints which has to be fulfilled by a part of the model space
during pattern matching.
</p><p>The following list of core constraints are interpreted by the pattern matcher:</p><div class="itemizedlist"><ul type="disc"><li><p><code class="computeroutput">entity(E)</code>: pattern variable E should be bound to an entity in the model space;</p></li><li><p><code class="computeroutput">relation(R)</code>: pattern variable R should be bound to a relation in the model space;</p></li><li><p><code class="computeroutput">from(R,X)</code>: relation R should lead from model element X;</p></li><li><p><code class="computeroutput">to(R, X)</code>: relation R should lead into model element X;</p></li><li><p><code class="computeroutput">super(X, Y)</code>: X is a supertype of Y or Y is a subtype of X;</p></li><li><p><code class="computeroutput">type(X, Y)</code>: X is type of Y, or Y is instance of X;</p></li><li><p>
<code class="computeroutput">in(X, Y)</code>:
X is a direct child of Y (Y is the parent of X) in the containment hierarchy of the model space.
</p></li><li><p>
<code class="computeroutput">below(X, Y)</code>:
X is a descendant of Y (Y is an ancestor of X) in the containment hierarchy of the model space.
</p></li></ul></div><p>Here the <code class="computeroutput">super</code> and the <code class="computeroutput">below</code>constraints are transitive.
</p><p>
In case of
<a href="def_PatternComposition.html" title="2.1.5.&nbsp;Pattern Composition">pattern composition</a>,
a predicate representing the invoked pattern is derived as a conjunction of the core constraints of its
body. A <a href="def_NegativePattern.html" title="2.1.3.&nbsp;Negative Pattern">negative pattern</a>
defines negative constraints: the pattern body can match only if none of the negative patterns can be
satisfied. In case of recursion, the fixpoint of the recursive predicate is calculated.
</p><p>
In case of multiple pattern bodies (OR-patterns), a different set of constraints is derived, and one of them
needs to be matched for a successful match of the pattern.
</p><p>
The pattern matching engine implements injective pattern matching, i.e. each pattern variable has to be
bound to different model elements in the model space unless (i) two
<a href="def_PatternVariable.html" title="2.1.6.&nbsp;Pattern Variable">pattern variables</a>
are explicitly assigned to the same model element by
<a href="def_PatternVariableAssignment.html" title="2.1.7.&nbsp;Pattern Variable Assignment">pattern variable assignment</a> or
(ii) both variables appear in as actual parameters of called subpatterns.
</p></td></tr></table></div><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution: Constraints"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Caution]" src="images/caution.png"></td><th align="left"><a name="def_PatternBody_Constraints"></a>Constraints</th></tr><tr><td valign="top" align="left"><p>All variables in the head of the pattern must appear in the pattern body</p><div class="itemizedlist"><ul type="disc"><li><p>locally in a model element, or</p></li><li><p>in a (positive or negative) pattern composition or</p></li><li><p>in a variable assignment or</p></li><li><p>in the check condition,</p></li></ul></div><p>
otherwise a compile-time error is generated. In case of OR-patterns, this rule applies to all pattern
bodies.
</p><p>
This is a significant change wrt. the previous versions of VIATRA where all pattern variables had to appear
locally or in the check condition.
</p><p>
The actual parameters of a pattern composition inside a pattern body are restricted to
<a href="def_PatternVariable.html" title="2.1.6.&nbsp;Pattern Variable">pattern variables</a>
.
</p></td></tr></table></div><div class="example"><a name="def_PatternBody_Example"></a><p class="title"><b>Example&nbsp;2.3.&nbsp;Overview of pattern body contents</b></p><div class="example-contents"><p>
<pre class="programlisting">
pattern myPattern(A,B,C,D) =
{
myType(A); // local pattern body element
B = A; // variable assignment
neg find myNestedPattern(C); // negative pattern composition
check (name(B) = D); // check condition
}
</pre>
</p></div><p></p></div><br class="example-break"><div class="highlights"><a name="def_PatternBody_DefinedIn"></a><p><b>Defined In:&nbsp;</b>
<a href="def_GraphPatternDef.html" title="2.1.1.&nbsp;Graph Pattern Definition">graph pattern definition</a>
</p></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="def_GraphPatternDef.html">Prev</a>&nbsp;</td><td align="center" width="20%"><a accesskey="u" href="sec_PatternDefinition.html">Up</a></td><td align="right" width="40%">&nbsp;<a accesskey="n" href="def_NegativePattern.html">Next</a></td></tr><tr><td valign="top" align="left" width="40%">2.1.1.&nbsp;Graph Pattern Definition&nbsp;</td><td align="center" width="20%"><a accesskey="h" href="index.html">Home</a></td><td valign="top" align="right" width="40%">&nbsp;2.1.3.&nbsp;Negative Pattern</td></tr></table></div></body></html>