Skip to content
Snippets Groups Projects
Commit bfa8febc authored by Johannes Mey's avatar Johannes Mey
Browse files

add ecore2relast tool and generate relast grammar from ecore model

parent 404e5c0b
No related branches found
No related tags found
No related merge requests found
File added
......@@ -77,37 +77,51 @@ task jarDrAst(type: Jar) {
with jar
}
task runDrAST(type: JavaExec, dependsOn:jar) {
task runDrAST(type: JavaExec, dependsOn: jar) {
group = "application"
description = 'run the DrAST visual debugger tool'
classpath = sourceSets.main.runtimeClasspath
main = 'de.tudresden.inf.st.statemachine.DrAstRunner'
}
def relastFiles = fileTree('src/main/jastadd/') {
include '**/*.relast' }.toList().toArray()
def relastFiles = fileTree('src/main/jastadd/') { include '**/*.relast' } +
fileTree('src/gen/jastadd/') { include '**/*.relast' }
String[] relastArguments = [
"../libs/relast.jar",
"--grammarName=./src/gen/jastadd/StatemachineGen",
"--grammarName=./src/gen/jastadd/StateMachine",
"--useJastAddNames",
"--listClass=ArrayList",
"--jastAddList=JastAddList",
"--resolverHelper",
"--file"
]
task preprocess(type: JavaExec) {
def ecoreFile = "./src/main/resources/StateMachine.ecore"
def relastFile = "./src/gen/jastadd/StateMachine.relast"
task ecoreToRelast(type: JavaExec) {
group = 'Build'
main = "-jar"
doFirst {
delete "src/gen/jastadd"
mkdir "src/gen/jastadd"
}
args "../libs/ecore2relast-0.1.jar", ecoreFile, relastFile
inputs.files file(ecoreFile)
outputs.files file(relastFile)
}
task preprocess(type: JavaExec) {
group = 'Build'
main = "-jar"
args relastArguments + relastFiles
inputs.files relastFiles
outputs.files file("./src/main/jastadd/StatemachineGen.ast"), file("./src/main/jastadd/StatemachineGen.jadd")
outputs.files file("./src/gen/jastadd/StateMachine.ast"), file("./src/gen/jastadd/StateMachine.jadd")
}
jastadd {
......@@ -181,9 +195,8 @@ task copyRagdoc(type: Copy, dependsOn: cleanRagdoc) {
eachFile { println it.file }
}
preprocess.dependsOn ecoreToRelast
generateAst.dependsOn preprocess
//generateAst.inputs.files file("./src/main/jastadd/StatemachineGen.ast"), file("./src/main/jastadd/StatemachineGen.jadd")
//compileJava.dependsOn jastadd
//
//// always run jastadd
//jastadd.outputs.upToDateWhen {false}
StateMachine ::= Element*;
abstract Element ::= <Label:String>;
State : Element;
Transition : Element;
rel Transition.From <-> State.Outgoing*;
rel Transition.To <-> State.Incoming*;
rel StateMachine.Initial -> State;
rel StateMachine.Final* -> State;
package de.tudresden.inf.st.statemachine;
import beaver.Parser;
import de.tudresden.inf.st.statemachine.jastadd.model.DotGraph;
import de.tudresden.inf.st.statemachine.jastadd.model.State;
import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine;
import de.tudresden.inf.st.statemachine.jastadd.model.Transition;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Set;
public class Main {
@SuppressWarnings("WeakerAccess")
public static Object DrAST_root_node;
@SuppressWarnings("WeakerAccess")
public static Object DrAST_root_node;
public static void main(String[] args) {
if (args.length == 0) {
// manual construction of a simple statemachine
// (S) -- 1 --> (B) -- 3 --> (E)
// ^ |
// \ /
// `---- 2 ----*
StateMachine stateMachine = new StateMachine();
State start = new State();
start.setLabel("S");
State stateB = new State();
stateB.setLabel("B");
State end = new State();
end.setLabel("E");
Transition t1 = new Transition();
t1.setLabel("1");
Transition t2 = new Transition();
t2.setLabel("2");
Transition t3 = new Transition();
t3.setLabel("3");
t1.setFrom(start);
t1.setTo(stateB);
t2.setFrom(stateB);
t2.setTo(start);
t3.setFrom(stateB);
t3.setTo(end);
stateMachine.addElement(start);
stateMachine.addElement(stateB);
stateMachine.addElement(end);
stateMachine.addElement(t1);
stateMachine.addElement(t2);
stateMachine.addElement(t3);
stateMachine.setInitial(start);
stateMachine.addFinal(end);
public static void main(String[] args) {
if (args.length == 0) {
// manual construction of a simple statemachine
// (S) -- 1 --> (B) -- 3 --> (E)
// ^ |
// \ /
// `---- 2 ----*
StateMachine stateMachine = new StateMachine();
State start = new State();
start.setLabel("S");
State stateB = new State();
stateB.setLabel("B");
State end = new State();
end.setLabel("E");
Transition t1 = new Transition();
t1.setLabel("1");
Transition t2 = new Transition();
t2.setLabel("2");
Transition t3 = new Transition();
t3.setLabel("3");
t1.setFrom(start);
t1.setTo(stateB);
t2.setFrom(stateB);
t2.setTo(start);
t3.setFrom(stateB);
t3.setTo(end);
stateMachine.addElement(start);
stateMachine.addElement(stateB);
stateMachine.addElement(end);
stateMachine.addElement(t1);
stateMachine.addElement(t2);
stateMachine.addElement(t3);
stateMachine.setInitial(start);
stateMachine.addFinal(end);
System.out.println(stateMachine.prettyPrint());
stateMachine.printSomeAnalysis();
DrAST_root_node = stateMachine;
} else {
// load the file given as first argument
try {
StateMachine stateMachine = ParserUtils.load(Paths.get(args[0]));
stateMachine.treeResolveAll();
System.out.println(stateMachine.prettyPrint());
stateMachine.printSomeAnalysis();
DrAST_root_node = stateMachine;
} else {
// load the file given as first argument
try {
StateMachine stateMachine = ParserUtils.load(Paths.get(args[0]));
stateMachine.treeResolveAll();
stateMachine.printSomeAnalysis();
System.out.println("> toDotGraph():");
System.out.println(stateMachine.toDot());
DrAST_root_node = stateMachine;
} catch (IOException | Parser.Exception e) {
e.printStackTrace();
}
}
}
System.out.println("> toDotGraph():");
System.out.println(stateMachine.toDot());
DrAST_root_node = stateMachine;
} catch (IOException | Parser.Exception e) {
e.printStackTrace();
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="statemachine" nsURI="http://www.example.org/statemachine" nsPrefix="statemachine">
<eClassifiers xsi:type="ecore:EClass" name="StateMachine">
<eStructuralFeatures xsi:type="ecore:EReference" name="element" upperBound="-1"
eType="#//Element" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="initial" lowerBound="1"
eType="#//State"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="final" upperBound="-1"
eType="#//State"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Element" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="State" eSuperTypes="#//Element">
<eStructuralFeatures xsi:type="ecore:EReference" name="outgoing" upperBound="-1"
eType="#//Transition" eOpposite="#//Transition/from"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="incoming" upperBound="-1"
eType="#//Transition" eOpposite="#//Transition/to"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Transition" eSuperTypes="#//Element">
<eStructuralFeatures xsi:type="ecore:EReference" name="from" lowerBound="1" eType="#//State"
eOpposite="#//State/outgoing"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="to" lowerBound="1" eType="#//State"
eOpposite="#//State/incoming"/>
</eClassifiers>
</ecore:EPackage>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment