Why should you use the Ecore2Xtext Wizard?
- You want your models to be in a syntax that humans can not only read but also understand.
- You want a model editor that offers all the convenience of a modern IDE.
- You already have an Ecore model but don't know how to start with Xtext.
- Your Ecore model is huge and you want a quick start with Xtext. You can easily fine-tune the syntax later on.
- Start the wizard by choosing New -> Xtext -> Xtext Project From Existing Ecore Models.
- Select the EMF generator models1 from your workspace for which you want a textual syntax and choose your root element's type.
- Fill in all the language metadata on the second page of the wizard. Remember the file extension.
- Click Finish and wait until Xtext has generated the two common Xtext plug-ins and the Xtext grammar for your language.
- Run the MWE2 workflow located in the same directory as the grammar. Now Xtext generates the language infrastructure (parser, editor, formatter etc) .
- Spawn a new Eclipse runtime workbench, create a sample Java Project, and open a new model file with the file extension you have chosen in the wizard. Play around and have fun with your new textual model editor.
Watch this short screencast to see it in action:
What is the generated syntax like?
Names of EClasses and EStructuralFeatures become keywords, containment is marked with curly braces, elements in lists are separated by commas, etc... Here's an example of an entity model in the generated language:
What if it doesn't work?
The grammar is the primary artifact of every Xtext language, but there are a couple of further services you might have to configure:
- A IQualifiedNameProvider to define how the fully qualified name of an element is derived.
- A IScopeProvider to define which elements are candidates for a cross reference.
Another geekish meta-confusing example
All right geeks, Ecore itself is defined in Ecore, so let's generate a textual syntax for Ecore and see how Ecore looks in that syntax! Only two adaptions of the generated code where necessary to get this editor:
(The '^' chars are automatically added by Xtext to distinguish identifiers from keywords, which of course collide a lot in this example) It is certainly not as complete as EMFatic, and it has a quite verbose syntax, but it could be the starting point for a nice textual Ecore editor.