Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "VIATRA2/Examples/VTCL/GraphPattern"
(→Pattern Matching Semantics) |
(→Pattern Matching Semantics) |
||
Line 11: | Line 11: | ||
* '''Shareable (or non-injective) pattern matching''': the injectivity condition is not checked for local pattern variables (thus two variables may be bound to the same value) unless a non-injectvity constraint (in the form of '''A =/= B''') is prescribed explicitly for a pair of variables. | * '''Shareable (or non-injective) pattern matching''': the injectivity condition is not checked for local pattern variables (thus two variables may be bound to the same value) unless a non-injectvity constraint (in the form of '''A =/= B''') is prescribed explicitly for a pair of variables. | ||
− | The following examples highlight the semantic corner cases using of pattern composition and injective pattern matching. | + | The following examples highlight the semantic corner cases using of pattern composition and injective pattern matching. As a example, we use |
+ | a simple state machine formalism (with states as entities and transitions as relations), which potentially contain loop transitions (where the source and target state of a transition is the same). | ||
<source lang="text"> | <source lang="text"> | ||
− | + | // A and B should be different, i.e. loop transitions are not matched | |
− | + | pattern childPatternInj1(A, B) = { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | pattern | + | |
state(A); | state(A); | ||
state.transition(T, A, B); | state.transition(T, A, B); | ||
Line 27: | Line 22: | ||
} | } | ||
− | shareable pattern | + | // A and B may be equal, loop transitions are matched |
+ | shareable pattern childPatternSha1(A, B) = { | ||
state(A); | state(A); | ||
state.transition(T, A, B); | state.transition(T, A, B); | ||
Line 33: | Line 29: | ||
} | } | ||
− | // Equivalent with | + | // Equivalent match set with childPatternInj1: A =/= B |
− | pattern | + | pattern childPatternInj2(A, B) = { |
− | find | + | find childPatternSha1(A, B); |
} | } | ||
+ | // Equivalent match set with childPatternInj1: A =/= B | ||
+ | shareable pattern childPatternSha2(A, B) = { | ||
+ | find childPatternSha1(A, B); | ||
+ | A =/= B; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | And now, for some more complex usage: | ||
+ | |||
+ | <source lang="text"> | ||
+ | pattern parentPatternInj(X, Y, Z) = { | ||
+ | find childPattern | ||
+ | |||
+ | } | ||
+ | |||
+ | shareable pattern parentPatternSha(X, Y, Z) = { | ||
+ | } | ||
</source> | </source> |
Revision as of 09:51, 25 May 2009
Overview: Graph patterns
Pattern Matching Semantics
NOTE: The shareable keyword and thus noninjective matches will be available from VIATRA R4 (expected by the end of June, 2009). This description serves as a documentation of the new features.
Patterns may be composed in VTCL a complex way by using the find construct. Moreover, the injectivity of pattern matching can be further controlled by using the new shareable keyword as follows:
- Injective pattern matching (default): the default behavior of the pattern matcher is that two local pattern variables cannot be bound to the same value (i.e. element in the model space). Pattern variable assignments (in the form of A=B) can enforce that the two variables take the same value during pattern matching.
- Shareable (or non-injective) pattern matching: the injectivity condition is not checked for local pattern variables (thus two variables may be bound to the same value) unless a non-injectvity constraint (in the form of A =/= B) is prescribed explicitly for a pair of variables.
The following examples highlight the semantic corner cases using of pattern composition and injective pattern matching. As a example, we use a simple state machine formalism (with states as entities and transitions as relations), which potentially contain loop transitions (where the source and target state of a transition is the same).
// A and B should be different, i.e. loop transitions are not matched pattern childPatternInj1(A, B) = { state(A); state.transition(T, A, B); state(B); } // A and B may be equal, loop transitions are matched shareable pattern childPatternSha1(A, B) = { state(A); state.transition(T, A, B); state(B); } // Equivalent match set with childPatternInj1: A =/= B pattern childPatternInj2(A, B) = { find childPatternSha1(A, B); } // Equivalent match set with childPatternInj1: A =/= B shareable pattern childPatternSha2(A, B) = { find childPatternSha1(A, B); A =/= B; }
And now, for some more complex usage:
pattern parentPatternInj(X, Y, Z) = { find childPattern } shareable pattern parentPatternSha(X, Y, Z) = { }