In this task, you will learn how to provide editors to your DSL in order to manipulate model instances conform to your DSL's metamodel. There are many ways to do so and as these techniques are independant from each other, you can experiment each of them according to your needs. However in this tutorial we will focus more on the textual editor. Advanced users (i.e.: those familiar with creating .xmi files from scratch) can directly jump to the texteditor generation section using dedicated framework.
Before all, let's create our first model instance with the dynamic instance :
Open the file ASMLogo.ecorediag inside the folder org.kermeta.kmlogo.logoasm.model/model.
Go to the outline view. Select the top level element inside your metamodel (for example here the LogoProgram as it is the entry point).
Right-click on this element and choose Create a dynamic instance.
Name your dynamic model "dots.xmi" and hit finish.
Using the tree-view editor is a way to manipulate model instances. Once you open the created ".xmi" file with the "Sample Reflective Ecore Model Editor" then you can add childs or sibling for the element to construct you model instance. At the end, you can obtain a model conform to the logo language in xmi format.
If you want to learn more, follow the complete example below or check out the other available examples
Right-click on the file "dots.xmi" and choose "open with .. > Sample Reflective Ecore Model Editor".
In the editor, unfold "...dots.xmi" and right-click on Block element. Choose New child > Instructions Right to position the turtle.
Then, right-click on "Instruction Right" and choose New child > Angle Constant to define the angle of the rotation. Select the element "Constant" and in the properties view (right clic show property view), set the Intetger Value to 90.
We set the fisrt instruction. In the editor, right-click and choose Validate to check wether your model instance newly created is conform to the defined metamodel.
Then you can keep on building your model instance : Right-click on "Right" element, choose New Sibling > Instructions penDown to tell the turtle to be "ready to write".
After that, Right-click on "PenDown" and choose New Sibling > Instructions Forward then like we did before, create the steps Constant child and set the value to 10. That tell the turtle to "draw" the line on 10 of the given metric (pixel).
Repeat above steps to complete your model instance like the illustration below and do not forget to Validate to check conformance from time to time.
Example 4.1. Creation of the dots.xmi
You have just finished creating your first model instance, save it and keep an eye on it as we are going to reuse it later in this tutorial.
A textual editor is also available in order to create a model instance conform to our metamodel and can be processed by the interpreter. In this example we will use EMFText (external link) to generate the concrete syntax of our metamodel.
Follow these steps to set up the concrete syntax of your language and its associated textual editor :
Create a java project and name it : org.kermeta.kmlogo.logoasm.emftexteditor. Create a folder concrete_syntax inside.
Back to the project org.kermeta.kmlogo.logoasm.tutorial, open the folder 1.metamodel/concrete_syntax.
Copy and paste the file ASMLogo.cs into the newly created folder org.kermeta.kmlogo.logoasm.emftexteditor/concrete_syntax/.
Right-clic on the file ASMLogo.cs and choose "Open With ..." > "EMFText cs editor". Analyse its content : it follows the structure of .cs file as described in the emftext CS language reference (external link).
Here, we defined the file extension of our DSL (logo), link it to our metamodel (through the nsUri) and define the style and the concrete rules for each meta-class concept that we want to map.
Tip | |
---|---|
If you meet with some errors, be sure to register your ecore and ensure that the path to your genmodel is correct. |
Right-click on ASMLogo.cs file and choose generate Text Ressource.
This would add two project in your project structure : org.emftext.commons.antlr3_1_1 and org.kermeta.kmlogo.logoasm.model.kmLogo.resource.logo.
(Update : Since EMFtext 1.3, this would add three projects in your project structure : org.emftext.commons.antlr3_2_0, org.kermeta.kmlogo.logoasm.model.kmLogo.resource.logo (core resource for texteditor) and org.kermeta.kmlogo.logoasm.model.kmLogo.resource.logo.ui (eclipse ui interraction).)
You have just generated the code for your text editor in "src" and "src-gen" of each project. Keep going through this tutorial to test it inside a real interpreter.
The graphical way to manipulate your metamodel can be done with the GMF editor.
For further information, please refer to the FSM tutorial on how to graphically edit your metamodel.