Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext grammer default data types
xtext grammer default data types [message #922126] Mon, 24 September 2012 19:14 Go to next message
Survivor Reward is currently offline Survivor Reward
Messages: 2
Registered: September 2012
Junior Member
I'm trying to define default data types in a grammar
//---------------------------------------------------------
Model:
    elements+=Element*;

Element:
     DataType | Entity;

DefaultDataType:
     'boolean' | 'char' | 'string' |'integer' | 'long' ;


DataType:
	'type' name=ID;

Entity:
	'entity' name=ID '{'
            attributes+=Attribute*
        '}';

Attribute:
       name=ID ':' type=[AttributeType|ID];

AttributeType:
	DefaultDataType | DataType | Entity;

//-------------------------------------------------------------------

It compiles OK with no errors!
Trying to create a model based on this grammar it gives error,extraneous input 'integer' [or 'string'] expecting RULE_ID, when using any of the DefaultDataType, string, integer, ... as an attribute type!
entity Person {
		id: integer
		name: string
	}

How to solve this problem?
How to export a set of default data types from the grammar to the instances?

Your help is highly appreciated
Re: xtext grammer default data types [message #922301 is a reply to message #922126] Mon, 24 September 2012 23:07 Go to previous message
Survivor Reward is currently offline Survivor Reward
Messages: 2
Registered: September 2012
Junior Member
Problem Solved!

Model:
    elements+=Element*;

Element:
     DataType | Entity;

DefaultDataType:
     default=('boolean' | 'char' | 'string' |'integer' | 'long') ;


DataType:
	'type' name=ID;

Entity:
	'entity' name=ID '{'
            attributes+=Attribute*
        '}';
// allow attribute type to have either an ID of attribute type or just attribute type
Attribute:
       name=ID ':' (type=AttributeType | typeID=[AttributeType|ID]);

AttributeType:
	DefaultDataType | DataType | Entity;

[Updated on: Mon, 24 September 2012 23:11]

Report message to a moderator

Previous Topic:Choose from one of multiple IJvmModelInferrer implementations at runtime
Next Topic:Language Integration Survey
Goto Forum:
  


Current Time: Mon Sep 15 04:20:10 GMT 2014

Powered by FUDForum. Page generated in 0.01629 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software