How to create a data model the textual DSL

From EdnaWiki
Jump to: navigation, search

How to create a EDNA datamodel file

An EDNA datamodel DSL file is a simple file with the extension .edna_datamodel. You can create this file with any editor.

If using Eclipse an Datamodel file is created with File / New / File on a project in your workspace. When the first .edna_datamodel file is created in a project you might be asked whether to add the Xtext nature to your project. Answer with "OK".

AddXtextNature.png

Language Concepts

Primitive Types

The following primitive types are built-in and map to their corresponding XSD types:

  • string
  • int
  • boolean
  • float
  • double

Complex Types

Complex types are introduced by the keywords "complex type" followed by their name. The content of a complex type is between curly brackets {}.

complex type XSData {
}

Inheritance

Complex type can be derived from another complex type by the keyword "extends" followed by the name of the extended type.

complex type XSDataDouble extends XSData {
}

Note: Circular inheritance is not checked until now.

Type Description

To give a description for a complex type add a string to the beginning of the content of the type body.

complex type XSDataDouble extends XSData {
   "Used for double typed values."
}

Attributes

A complex type can have a list of Attributes. Each Attribute has at least a name and a type, seperated by a colon. The type can be either the name of a Primitive Type or the name of another Complex Type.

complex type XSDataDouble extends XSData {
   value : double
}

By default attributes are mandatory and single-valued.

To mark an attribute as optional add the "optional" keyword add the end of the attribute declaration.

complex type XSDataAngularSpeed extends XSData {
   unit : XSDataString optional
}

An attribute can be marked as multi-valued by adding "[]" brackets after the type like in array declarations.

complex type XSDataIndexingResult extends XSDataResult {
   image: XSDataImage[]
}

Packages

Packages group elements into a namespace. Packageable elements are Complex Types and Packages. A package is denoted by the `package` keyword, followed by the package name and opening curly brackets.

package kernel {
  package subpackage {
    complex type XSDataSomething extends XSData { ... }
  }
}

Miscalleneous

Comments

The language supports single-line and multi-line comments with notation similar to C/Java:

// This is a single-line comment
/* 
 this
 is a
 multi-line comment
*/

Keyword escaping

In some cases the name of a model element might collide with a recognized keyword. In these cases the element's name can be prefixed with the '^' character, which escapes the name from the keyword.