Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] Bring rule call and cross-reference under one feature
[SOLVED] Bring rule call and cross-reference under one feature [message #1754924] Fri, 24 February 2017 07:44 Go to next message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
Hi all,

In my DSL, I have types, which can be complex (i.e. objects) or simple (i.e. primitives like string, integer etc.)

A source in my DSL looks like this:

type SomeType {
    string primitiveAttribute
}

type OtherType {
    string otherPrimitiveAttribute
    SomeType complexAttribute
}


The grammar with which I achieve this is the following:

SimpleType:
	type = ('long' | 'string' | 'bool' | 'decimal' | 'integer')
;

ComplexType:
	'type' name = ID '{'
		(fields += TypeField)*
	'}'
;

TypeField:
	typeDef = TypeDef fieldName = ID
;

TypeDef:
	(simpleType = SimpleType | typeRef = [ComplexType])
;


As you can see, SimpleType and ComplexType are assigned to two different features (I hope I get the terminology right), so when I generate something from them, I always have to handle these separately, checking if one of them is null, and so on. Also, their interfaces generated by Xtext are of course derived from EObject.

Is it possible to define a new rule which can hold SimpleType and ComplexType together in the TypeDef rule (so no null check is needed for their presence), and where both of them can derive from the same parent interface? It would be much better to have a common abstraction for them in my generator design.

Thank you.

[Updated on: Fri, 24 February 2017 08:36]

Report message to a moderator

Re: Bring rule call and cross-reference under one feature [message #1754927 is a reply to message #1754924] Fri, 24 February 2017 07:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
thy not use inhertiance?

TypeDef:
SimpleType | ComplexTypeRef
;
ComplexTypeRef:
typeRef = [ComplexType]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Bring rule call and cross-reference under one feature [message #1754932 is a reply to message #1754927] Fri, 24 February 2017 08:35 Go to previous message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
Great, thanks! I could have guessed that.
Previous Topic:Problems when referencing Ecore elements using an imported Ecore model
Next Topic:Implicitly add method call to generated interface.
Goto Forum:
  


Current Time: Fri Apr 26 09:28:39 GMT 2024

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

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

Back to the top