[SOLVED] Bring rule call and cross-reference under one feature [message #1754924] |
Fri, 24 February 2017 07:44  |
Tam Gom 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02000 seconds