<
From version < 4.1 >
edited by msp
on 2012/10/31 19:09
To version < 5.1 >
edited by msp
on 2012/10/31 19:58
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -10,11 +10,43 @@
10 10  
11 11  An Xtext grammar is always related to a specific EMF meta model. The grammar defines a concrete syntax in which instances of the meta model (the abstract syntax) can be serialized and stored. Xtext supports two ways of linking a grammar with a meta model: either creating a grammar for an existing meta model, or creating a grammar first and generating a meta model out of it. Here we will use the former approach, reusing the meta model for Turing Machines that you already defined earlier.
12 12  
13 +1. Install the //Xtext Antlr Runtime Feature// from [[http:~~/~~/download.itemis.de/updates/>>url:http://download.itemis.de/updates/||shape="rect"]]
13 13  1. //File// → //New// → //Project...// → //Xtext// → //Xtext Project From Existing Meta Models// → //Next// → //Add...// → turing.genmodel → //OK//
14 14  1. Select your top-level model element as "//Entry rule//", e.g. //TuringMachine// → //Next// → enter the following values:\\
15 -1*. //Project name~:// de.cau.cs.rtprak.turing.text
16 +1*. //Project name~:// de.cau.cs.rtprak.login.turing.text (like in previous tutorials, replace "login" by your login name)
16 16  1*. //Location~:// your repository path
17 -1*. //Name~:// de.cau.cs.rtprak.turing.text.Turing
18 +1*. //Name~:// de.cau.cs.rtprak.login.turing.text.Turing
18 18  1*. //Extensions~:// tuxt (the file extension under which your text files will be stored)
19 19  1*. Uncheck //Create SDK feature project// (not required)
20 -1. Finish → an editor is opened with a predefined grammar. The fourth line should contain an import statement followed by the namespace URI of your meta model, which is probably marked with an error. The problem here is that the meta model is not loaded in the Eclipse instance you are using for development. Fix this problem by replacing the URI by the workspace path of your Turing Machines ecore model, e.g. {{code language="none"}}"platform:/resource/de.cau.cs.rtprak.turing/model/turing.ecore"{{/code}}
21 +1. Finish → an editor is opened with a predefined grammar (Turing.xtext). The fourth line should contain an import statement followed by the namespace URI of your meta model, which is probably marked with an error. The problem here is that the meta model is not loaded in the Eclipse instance you are using for development. Fix this problem by replacing the URI by the workspace path of your Turing Machines ecore model, e.g. {{code language="none"}}"platform:/resource/de.cau.cs.rtprak.login.turingmodel/model/turing.ecore"{{/code}}
22 +1. The Turing.xtext file is located in the package de.cau.cs.rtprak.login.turing.text together with a //Modeling Workflow Engine// file, which can be used to configure code generation. Right-click GenerateTuring.mwe2 and select //Run As// → //MWE2 Workflow//. If you get an error message like "//*ATTENTION* It is recommended to use the ANTLR 3 parser generator//" in the console, type //n// and install Antlr from the update site.
23 +1. Now a great amount of Java code should have been generated. Add the new plugins to your Eclipse run configuration and start it.
24 +1. In the new Eclipse instance: //File// → //New// → //File// and name it test.tuxt (when asked to add the Xtext nature, hit //Yes//).
25 +1. (((
26 +Use ctrl + space for getting content assist to create a valid model following the predefined grammar. The syntax will probably look similar to this:
27 +
28 +{{noformat}}
29 +TuringMachine {
30 + states {
31 + State blub {
32 + },
33 + State blah {
34 + outgoing {
35 + Transition {
36 + target blub
37 + }
38 + }
39 + }
40 + }
41 +}
42 +{{/noformat}}
43 +)))
44 +
45 +The predefined grammar is not very nice. That's why now your creative part comes into play. Change the Xtext grammar file to a grammar of your liking, which should support a simple and readable syntax for Turing Machines. All required documentation for this task is found at [[http:~~/~~/www.eclipse.org/Xtext/>>url:http://www.eclipse.org/Xtext/||shape="rect"]].
46 +
47 +Some hints:
48 +
49 +* The predefined grammar contains one grammar rule for each meta model class. This general structure can be kept in most cases.
50 +* Ecore enumerations (EEnum) must be defined with an {{code language="none"}}enum{{/code}} grammar rule (see documentation). This is not correct in the predefined grammar and is marked with a TODO note.
51 +
52 +
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -2982416
1 +2982418
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982416/Textual Modeling with Xtext
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982418/Textual Modeling with Xtext