These are the key takeaways from Chapter 2 of Implementing Domain-Specific Languages with Xtext and Xtend – Second Edition. Chapter 2. Creating Your First Xtext Language
Creating a hello world Xtext project in Eclipse
- File -> New -> Project -> Xtext -> Xtext Project
- Fill out Project name, Name and Extensions
- Finish
The project solution contains the following projects
- org.example.entities – the main project where you’ll add your dsl definitions
- org.example.entities.tests – contains the JUnit test for the main project
- org.example.entities.ide – this contains ide specific component for the UI
- org.example.entities.ui – contains UI components for the Eclipse UI
- org.example.entities.ui.tests – the unittest project for the UI project
You’ll have the basic hello world in your xtext file in org.example.entities
grammar org.example.entities.Entities with org.eclipse.xtext.common.Terminals
generate entities "http://www.example.org/entities/Entities"
Model:
greetings+=Greeting*;
Greeting:
'Hello' name = ID '!';
Once run the Generate Xtext Artifact by right-clicking on GenerateEntities.mwe2. Afterwards right-clicking the xtext file and run it every time you have completed a modification. It’ll generate several new folder with the generated files like the src-gen folder. Run As -> Generate Xtext Artifacts
Xtext will generate many artifacts for the DLS and other IDE tooling.
- AST – abstract syntax tree
- BNF – Backus Normal Form (like pseudo code)