Child pages
  • Textual Modeling with Xtext
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

This tutorial presents the Xtext framework, a toolsuite for the generation of plain text based model editors. Such textual editors provide syntax highlighting, content assist (ctrl-space), an outline, and much more out-of-the-box. You will start by creating a textual syntax for Turing Machines.

Contents

Creating a Grammar

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.

  1. File → New → Project... → Xtext → Xtext Project From Existing Meta Models → Next → Add... → turing.genmodel → OK
  2. Select your top-level model element as "Entry rule", e.g. TuringMachine → Next → enter the following values:
    • Project name: de.cau.cs.rtprak.turing.text
    • Location: your repository path
    • Name: de.cau.cs.rtprak.turing.text.Turing
    • Extensions: tuxt (the file extension under which your text files will be stored)
    • Uncheck Create SDK feature project (not required)
  3. 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. "platform:/resource/de.cau.cs.rtprak.turing/model/turing.ecore"
  • No labels