C-like multiple declaration [message #1793679] |
Tue, 14 August 2018 04:29 |
Fabian G. Messages: 60 Registered: May 2010 Location: Christchurch (NZ) |
Member |
|
|
Hi,
I'm trying to allow multiple declarations of the same type, a bit like in C or Java. However, I can't find a clean way to do it directly in the grammar. At the moment I have the "usual" way (snippet):
Declaration returns Declaration:
'var' name=ID ':' type = [Type];
So, when declaring stuff, considering that I declared a type Integer, I write:
var anInteger : Integer
var another : Integer
The idea is to simply have
var anInteger, another : Integer
But I'd like to instantiate as many Declaration EObjects as I declare elements, i.e, I do not want to have a list of names for one Declaration (using the usual parameter-like pattern below), but triggering the creation of multiple Declaration from the grammar.
Declaration returns Declaration:
'var' name+=ID (',' name+=ID)* ':' type = [Type];
Is there a way to do so directly from the grammar ? Or, if not possible, where do I have the hand to transform my list of names into a list of EObjects?
Thanks,
Fabian
|
|
|
|
Re: C-like multiple declaration [message #1793738 is a reply to message #1793680] |
Tue, 14 August 2018 23:47 |
Fabian G. Messages: 60 Registered: May 2010 Location: Christchurch (NZ) |
Member |
|
|
As suggested in your post (method 2), I went for the inline M2M approach but despite the binding of my own IDerivedStateComputer seems to work (at least the bindIDerivedStateComputer get called in the RuntimeModule), the methods in there are not (debugged with println, got nuts). The editor/validator is complaining because there is no value in the type feature. The code below doesn't get called:
class IoTDSLDerivedState implements IDerivedStateComputer {
override discardDerivedState(DerivedStateAwareResource resource) {
println("called discardDerivedState")
resource.allContents.filter(typeof(DeclaredElement)).forEach [
type = null
]
}
override installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
println("called installDerivedState")
resource.allContents.filter(typeof(DeclaredElement)).forEach [
type = (eContainer as Declaration).type
]
}
}
The grammar snippet:
Declaration returns Declaration:
'var' instances += DeclaredElement (',' instances += DeclaredElement)* ':' type = [Type]
;
DeclaredElement returns DeclaredElement:
name=ID
;
Also, I believe I do not need to add the structural features in my own postprocessor since I rely on an existing MM where the type relationship already exists for the DeclaredElement and I just want it to be populated at runtime.
Any idea? Thanks!
[Updated on: Wed, 15 August 2018 05:25] Report message to a moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds