Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding built-in types to the domain model example
Adding built-in types to the domain model example [message #848415] Wed, 18 April 2012 07:47 Go to next message
Louis van der Stam is currently offline Louis van der StamFriend
Messages: 2
Registered: April 2012
Junior Member
Hi,

I'm quite new to xText. Currently I'm working my way through the tutorial and making modifications to examine different behavior.

With the domain model example, I have been trying to add built-in primitive types (string, int, boolean) instead of requiring them to be defined through the "DataType" rule. I want to remove the "DataType" rule from the model.

My attempts have been unsuccessful thus far. Where my main problem seems to be to get the build-in types recognised as a subtype of "Type" and get the editor to show the built-in types as an alternative.

So my question is what approaches are there to achieve the addition of built-in types to the domain model example and if there are multiple what would be the preffered option. Examples of the model modification and/or code would be appriciated.

Regards,

Louis
Re: Adding built-in types to the domain model example [message #848455 is a reply to message #848415] Wed, 18 April 2012 08:33 Go to previous messageGo to next message
Holger Schill is currently offline Holger SchillFriend
Messages: 75
Registered: July 2009
Member
Hi Louis,

if I understood you right you would like to reference JavaTypes? There
is a common way
http://www.eclipse.org/Xtext/documentation/2_0_0/199a-jvmtypes.php.

As alternative you could extens xbase
http://www.eclipse.org/Xtext/documentation/2_0_0/199e-xbase-language-reference.php.

The shipped DomainModelExample since Xtext 2.0 extends xbase so you
might have a look here.

Cheers,

Holger


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Adding built-in types to the domain model example [message #848487 is a reply to message #848455] Wed, 18 April 2012 09:18 Go to previous messageGo to next message
Louis van der Stam is currently offline Louis van der StamFriend
Messages: 2
Registered: April 2012
Junior Member
Hello Holger,

thank you for your response.

- if I understood you right you would like to reference JavaTypes?
The types I gave were just examples and most likely they would be closely resembling the primitive types in many programming languages. So yes they are JavaTypes, but no I'm not trying to reference all JavaTypes.

- There is a common way [link not allowed] www.eclipse.org/Xtext/documentation/2_0_0/199a-jvmtypes.php.
For me the link doesn't work, I guess you are pointing me to the xText documentation.

- As alternative you could extens xbase [link not allowed] www.eclipse.org/Xtext/documentation/2_0_0/199e-xbase-language-reference.php.
For me the link doesn't work, I guess you are pointing me to the xText documentation.

- The shipped DomainModelExample since Xtext 2.0 extends xbase so you might have a look here.
I haven't worked through the tutorials completely... But I'have skipped ahead and looked at the shipped example. With the example, when I create a new property, I get a huge list of JAVA types when I hit CTRL-<space>. I need only the primitive language types and the Entities defined in the model to be available as the type for an entity. So it seems to me that the java type mapping is a bit to much for me.

Can you suggest another way to achieve the built-in types without importing the all JavaTypes?

Regards,

Louis
Re: Adding built-in types to the domain model example [message #848682 is a reply to message #848487] Wed, 18 April 2012 13:27 Go to previous messageGo to next message
Holger Schill is currently offline Holger SchillFriend
Messages: 75
Registered: July 2009
Member
Hello Luis,

remove the dots at the end of the URLs and the links should work.

If you have the need to have a real reference to the primitive types
www.eclipse.org/Xtext/documentation/2_0_0/199a-jvmtypes.php should be
the way to go. Just filter for types in java.lang or something like this
in the scopeProvider.
If there is no need for you to have a real reference you could establish
a small grammar to define types and reference them in the
domainModelExample with a crossreference and ship the file with the
defined types as library with your language.

Cheers,
Holger

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Adding built-in types to the domain model example [message #849919 is a reply to message #848682] Thu, 19 April 2012 15:22 Go to previous messageGo to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
Messages: 17
Registered: April 2012
Junior Member
I have similar problem: I would like to add my custom/built-in/atomic types to the default tutorial grammar:

Domainmodel:
  (elements += AbstractElement)*
;

PackageDeclaration:
  'package' name = QualifiedName '{'
    (elements += AbstractElement)*
  '}'
;

AbstractElement:
  PackageDeclaration | Type | Import
;

QualifiedName:
  ID ('.' ID)*
;

Import:
  'import' importedNamespace = QualifiedNameWithWildcard
;
  
QualifiedNameWithWildcard:
  QualifiedName '.*'?
;
  
Type:
  DataType | Entity
;
  
DataType:
  'datatype' name=ID
;
 
Entity:
  'entity' name = ID 
              ('extends' superType = [Entity | QualifiedName])?
  '{'
    (features += Feature)*
  '}'
;
 
Feature:
  (many ?= 'many')? name = ID ':' type = [Type | QualifiedName]
;



I have tried many approaches but still failed. For instance can someone explain why the following modification does not work (the generated editor error message: "extraneous input 'bool' expecting RULE_ID"):

Type:
  (DataType | Entity | PrimitiveType)
;

PrimitiveType:
	{PrimitiveType}('integer'|'float'|'string'|'bool')
;
Re: Adding built-in types to the domain model example [message #850681 is a reply to message #849919] Fri, 20 April 2012 08:24 Go to previous message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
Messages: 17
Registered: April 2012
Junior Member
Finally I found the solution. Basically the problem was caused by a wrong cross-referencing to [Type]. Now a few new rules have been introduced and the cross-referencing is performed outside the Feature rule (this post was helpful: www.eclipse.org/forums/index.php/m/523812/).

Here is the modified Xtext tutorial with added built-in/atomic/custom types:
Domainmodel:
  (elements += AbstractElement)*
;

PackageDeclaration:
  'package' name = QualifiedName '{'
    (elements += AbstractElement)*
  '}'
;

AbstractElement:
  PackageDeclaration | Type | Import
;

QualifiedName:
  ID ('.' ID)*
;

Import:
  'import' importedNamespace = QualifiedNameWithWildcard
;
  
QualifiedNameWithWildcard:
  QualifiedName '.*'?
;
  
Type:
  DataType | Entity
;

TypeRef :
EntityRef | BuiltInRef;

EntityRef :
entity=[Entity | QualifiedName];

BuiltInRef :
name=('integer'|'float'|'string'|'bool'|'date') 
;
  
DataType:
  'datatype' name=ID
;
 
Entity:
  'entity' name = ID 
              ('extends' superType = [Entity | QualifiedName])?
  '{'
    (features += Feature)*
  '}'
;
 
Feature:
  (many ?= 'many')? name = ID ':' type = TypeRef
;



Moderator: I think you can mark this post as [SOLVED]
Previous Topic:Check for syntax errors before formatting.
Next Topic:Using Xtext and Xtend
Goto Forum:
  


Current Time: Sat Jul 11 09:17:56 GMT 2020

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

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

Back to the top