Skip to main content



      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 02:44 Go to next message
Eclipse UserFriend
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 03:36] by Moderator

Re: Bring rule call and cross-reference under one feature [message #1754927 is a reply to message #1754924] Fri, 24 February 2017 02:59 Go to previous messageGo to next message
Eclipse UserFriend
thy not use inhertiance?

TypeDef:
SimpleType | ComplexTypeRef
;
ComplexTypeRef:
typeRef = [ComplexType]
Re: Bring rule call and cross-reference under one feature [message #1754932 is a reply to message #1754927] Fri, 24 February 2017 03:35 Go to previous message
Eclipse UserFriend
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 May 16 18:16:51 EDT 2025

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

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

Back to the top