Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitris Kolovos2022-09-24 18:06:48 +0000
committerDimitris Kolovos2022-09-24 18:06:48 +0000
commitc191d0401375eb111a14e5c67060802a2995f3c9 (patch)
treebc9007a4624172bb38a878f30a0c0619714c3c2c
parent92ee0c3eff5d98f93421d8775d7a76f3b2dfa9f5 (diff)
downloadorg.eclipse.epsilon-c191d0401375eb111a14e5c67060802a2995f3c9.tar.gz
org.eclipse.epsilon-c191d0401375eb111a14e5c67060802a2995f3c9.tar.xz
org.eclipse.epsilon-c191d0401375eb111a14e5c67060802a2995f3c9.zip
Added EPL/EVL standalone example
-rw-r--r--examples/org.eclipse.epsilon.examples.standalone/pom.xml6
-rw-r--r--examples/org.eclipse.epsilon.examples.standalone/src/org/eclipse/epsilon/examples/standalone/epl/EplEvlStandaloneExample.java44
2 files changed, 50 insertions, 0 deletions
diff --git a/examples/org.eclipse.epsilon.examples.standalone/pom.xml b/examples/org.eclipse.epsilon.examples.standalone/pom.xml
index e987eca13..195e4d5d1 100644
--- a/examples/org.eclipse.epsilon.examples.standalone/pom.xml
+++ b/examples/org.eclipse.epsilon.examples.standalone/pom.xml
@@ -76,6 +76,12 @@
<version>${epsilon.version}</version>
<scope>${epsilon.scope}</scope>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.epsilon</groupId>
+ <artifactId>org.eclipse.epsilon.epl.engine</artifactId>
+ <version>${epsilon.version}</version>
+ <scope>${epsilon.scope}</scope>
+ </dependency>
<dependency>
<groupId>org.eclipse.epsilon</groupId>
<artifactId>org.eclipse.epsilon.flexmi</artifactId>
diff --git a/examples/org.eclipse.epsilon.examples.standalone/src/org/eclipse/epsilon/examples/standalone/epl/EplEvlStandaloneExample.java b/examples/org.eclipse.epsilon.examples.standalone/src/org/eclipse/epsilon/examples/standalone/epl/EplEvlStandaloneExample.java
new file mode 100644
index 000000000..ff74263b5
--- /dev/null
+++ b/examples/org.eclipse.epsilon.examples.standalone/src/org/eclipse/epsilon/examples/standalone/epl/EplEvlStandaloneExample.java
@@ -0,0 +1,44 @@
+package org.eclipse.epsilon.examples.standalone.epl;
+
+import org.eclipse.epsilon.emc.plainxml.PlainXmlModel;
+import org.eclipse.epsilon.epl.EplModule;
+import org.eclipse.epsilon.epl.execute.model.PatternMatchModel;
+import org.eclipse.epsilon.evl.EvlModule;
+
+public class EplEvlStandaloneExample {
+
+ public static void main(String[] args) throws Exception {
+
+ // Load a tree-like XML model
+ PlainXmlModel xmlModel = new PlainXmlModel();
+ xmlModel.setXml("<node value=\"1\"><node value=\"2\"/></node>");
+ xmlModel.load();
+
+ // Find parent-child pairs using EPL
+ EplModule epl = new EplModule();
+ epl.parse("pattern ParentChildPair parent : t_node, child : t_node from: parent.children {}");
+ epl.getContext().getModelRepository().addModel(xmlModel);
+
+ // The result of pattern matching is a model itself
+ PatternMatchModel patternMatchModel = (PatternMatchModel) epl.execute();
+
+ // Validate the pattern model with EVL
+ EvlModule evl = new EvlModule();
+ evl.parse("context ParentChildPair { constraint ParentValueGreaterThanChild { check : self.parent.i_value > self.child.i_value message : self.parent.i_value + ' must be greater than ' + self.child.i_value}}");
+
+ // Make both the pattern model and the original model available to EVL
+ evl.getContext().getModelRepository().addModel(patternMatchModel);
+ evl.getContext().getModelRepository().addModel(xmlModel);
+
+ // Execute the EVL constraint
+ evl.execute();
+
+ // The constraint should fail because the value of the top node is
+ // greater than the value of its child
+ evl.getContext().getUnsatisfiedConstraints().stream().forEach(uc -> {
+ System.out.println(uc.getMessage());
+ });
+
+ }
+
+}

Back to the top