| Adding built-in types to the domain model example [message #848415] |
Wed, 18 April 2012 03:47  |
Louis van der Stam 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 #848682 is a reply to message #848487] |
Wed, 18 April 2012 09:27   |
Holger Schill Messages: 60 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 #850681 is a reply to message #849919] |
Fri, 20 April 2012 04:24  |
Mariusz Mariusz 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]
|
|
|
Powered by
FUDForum. Page generated in 0.08465 seconds