Queen's Logo

Beyond Code: An Introduction to Model-Driven Software Development (CISC 844, Winter 2025)

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.
  1. 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:
  2. 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:
  3. 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:
  4. 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:
  5. 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:
  6. Small Java
    • sublanguage of Java
    • illustrates Java code generation, scoping, validation (type conformance, dead code, cyclic class hierarchy), testing (UI and generated code)
    • example:
  7. 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.

More information on DSLs with Xtext

Last modified: Sun Jan 05 2025 12:51:07