 |
|
Beyond Code: An Introduction to Model-Driven Software Development (CISC 836, Winter 2021)
Xtext Sample DSLs
|
The sample DSLs below assume the Eclipse IDE for Java and DSL Developers (version 2020-12 R, it will contain Xtext version 2.24 and all other software Xtext depends on).
See the beginning of Assignment 4 for information on
how to obtain and install it, and how use these sample DSLs. The origin of these DSLs is
as follows:
All artifacts are made available under the terms of the Eclipse Public Licence v1.0.
- Greetings:
- 'Hello World' of Xtext
- illustrates basic support for editing, validation, and generation
- language infrastructure artifacts generated by Xtext from the DSL grammar to explore:
ECore model (mydsl/model/generated/MyDsl.ecore), EMF code (mydsl/src-gen/mydsl.myDsl), Antlr parser (mydsl/src-gen/mydsl.parser.antlr), validation (mydsl/src/mydsl.validation), and generation (mydsl/src/mydsl.generator)
- example:
- Task assignment:
- language for specifying tasks and assigning people, priorities, and durations to them
- illustrates generation of HTML and text artifacts from specifications, validation,
support for arithmetic and boolean expressions in the grammar, and scoping(i.e., restricted visibility)
- example:
- Entities:
- textual language for class modeling (i.e., 'class diagrams')
- demonstrates Java code generation (org.example.entities.generator), validation (cyclic subclassing), and quick fixes (org.example.entities.ui.quickfix) to remove supertypes to break cycles and declare missing entities
- example:
- Arithmetics:
- calcuator for arithmetic expressions with support for user-defined functions
- high-level description can be found here
- illustrates the use of Xtext to implement an interactive interpreter (arithmetics.interpreter) using automatic edit of the specification to output evaluation results (arithmetics.ui.autoedit), content-assist to propose function arguments, and quick fixes to, e.g., normalize constant expressions
- also showcases 'multiple dispatch' in Xtend, i.e., method resolution based on the runtime type of arguments (see method internalEvaluate in class Calculator.xtend in package src/org.eclipse.xtext.example.arithmetics.interpreter
- example:
- State machines:
- simple textual state machine language originally due to Martin Fowler
- high-level description can be found here
- illustrates the use of Xtext for the generation of executable Java code from an artifact expressed in the DSL
- example:
- Small Java
- sublanguage of Java
- illustrates Java code generation, scoping, validation (type conformance, dead code, cyclic class hierarchy), testing (UI and generated code)
- example:
- Urml:
- sublanguage of UML-RT as used in Assignment 4
- illustrates interactive interpretation and the generation of executable Java code from artifacts expressed in the DSL
- example:
Download
All artifacts are made available under the terms of the Eclipse Public Licence v1.0.
- DSL definitions: Projects defining the DSLs below and supporting tooling can be found here. Import into Eclipse using 'Existing Projects into Workspace'.
- Instances of the DSLs: Artifacts expressed in the DSLs (i.e., 'specifications', 'programs, or 'models') can be found here. Import into the 'runtime workspace' of the new Eclipse instance running the DSL plugins created by Xtext.
More information on DSLs with Xtext
Last modified: Tue Feb 09 2021 12:41:29