scope of custom xbase expression [message #1076142] |
Tue, 30 July 2013 19:51 |
andrea rossi Messages: 23 Registered: April 2013 |
Junior Member |
|
|
Hi,
this is part of my grammar :
grammar org.xtext.example.dsl.Dsl with org.eclipse.xtext.xbase.Xbase
generate dsl "http://www.xtext.org/example/mydsl/MyDsl"
import 'http://www.eclipse.org/xtext/xbase/Xbase' as xbase
Model:
'package' name = QualifiedName
importSection = XImportSection?
elements+= AbstractBehaviour*;
Message returns xbase::XExpression:
SendMessage | ReceiveMessage
;
SendMessage returns xbase::XExpression:
{SendMessage}
'send' 'message' name = ValidID '{'
(('sender=' sender = STRING)? &
('content=' content = STRING)? &
//('language' '=' language = STRING)? &
//('ontology' '=' ontology = STRING)? &
('performative=' performative = Performative) &
('receivers' '{' (receivers += (MessageReceivers)+) '}' ) )
'}'
;
MessageReceivers :
'receiver =' receiver = STRING
;
enum Performative :
REQUEST | INFORM | QUERY_IF | CFP | PROPOSE | ACCEPT_PROPOSAL
;
AbstractBehaviour :
Behaviour
;
Behaviour :
'behaviour' name=ValidID 'is' typeB = 'Behaviour'
(body=XBlockExpression)
;
XExpressionInsideBlock returns xbase::XExpression:
XVariableDeclaration | XExpression | Message;
ReceiveMessage returns xbase::XExpression :
{ReceiveMessage} 'receive' 'message' name = ValidID ('filter=' filter=(Expression))? 'do' body= XBlockExpression
;
in my dsl I extended xbase expression(SendMessage and ReceiveMessage)then
I extended jvmModelinferr and xbaseCompiler to translate them into relative java code.
this is an example of what I would like to obtain in my dsl editor :
behaviour B is Behaviour {
receive message msg
do {
msg.getcontent();
}
}
I would like to use msg (filed name of ReceiveMessage)into the block as variable(i.e ACLMessage variable)
But ReceiveMessage is my custom xbase expression and I don't know as set right scope without use jvmModelInferr
Which class do I have to extend to set the scope of my xbase expressions?
Any suggestion? example?
thank you in advance
[Updated on: Tue, 30 July 2013 19:54] Report message to a moderator
|
|
|
|
Re: scope of custom xbase expression [message #1078968 is a reply to message #1076744] |
Sat, 03 August 2013 22:16 |
andrea rossi Messages: 23 Registered: April 2013 |
Junior Member |
|
|
thank you for your reply , it helped me but I have a problem
I rewrite my Receive message in this way :
ReceiveMessage returns xbase::XExpression :
{ReceiveMessage} 'receive' 'message' name = ValidID 'vd' vd = XVariableDeclaration
('filter=' filter=(Expression))? 'do' body= XBlockExpression
;
I add the field vd(the declaration that must be visible in the body of ReceiveMessage)
I write my custom typecomputer :
class DslTypeComputer extends XbaseTypeComputer {
@Inject extension JvmTypesBuilder
override computeTypes(XExpression expression, ITypeComputationState state) {
if(expression instanceof SendMessage) {
_computeTypes(expression as SendMessage, state);
} else if (expression instanceof ReceiveMessage){
_computeTypes(expression as ReceiveMessage,state)}
else {
super.computeTypes(expression, state)
}
}
protected def _computeTypes(SendMessage expression, ITypeComputationState state) {
//super._computeTypes(expression as XExpression, state)
state.acceptActualType(getTypeForName(typeof(Void), state))
}
protected def _computeTypes(ReceiveMessage expression, ITypeComputationState state) {
/* here I call addLocalToCurrentScope(XvariableDeclaration, state) and pass vd field */
}
}
it works till here but if I want to remove the field vd from my grammar , how can I do?
I tried to create my XVariableDeclaration in _computeTypes(ReceiveMessage) and then called addLocalTocurrentScope but it doesnt work..
[Updated on: Sat, 03 August 2013 22:22] Report message to a moderator
|
|
|
Re: scope of custom xbase expression [message #1081401 is a reply to message #1078968] |
Wed, 07 August 2013 07:26 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Am 04.08.13 00:16, schrieb andrea rossi:
> thank you for your reply , it helped me but i have a problem
> i rewrite my Receive message in this way :
>
> ReceiveMessage returns xbase::XExpression : {ReceiveMessage} 'receive'
> 'message' name = ValidID 'vd' vd = XVariableDeclaration ('filter='
> filter=(Expression))? 'do' body= XBlockExpression
> ;
>
>
>
> i add the field vd(the declaration that must be visible in the body of
> ReceiveMessage)
> i write my custom typecomputer :
>
> class DslTypeComputer extends XbaseTypeComputer {
>
> @Inject extension JvmTypesBuilder
>
> override computeTypes(XExpression expression, ITypeComputationState
> state) {
> if(expression instanceof SendMessage) {
> _computeTypes(expression as SendMessage, state);
> } else if (expression instanceof ReceiveMessage){
> _computeTypes(expression as ReceiveMessage,state)}
> else {
> super.computeTypes(expression, state)
> }
> }
>
> protected def _computeTypes(SendMessage expression,
> ITypeComputationState state) {
> //super._computeTypes(expression as XExpression, state)
> state.acceptActualType(getTypeForName(typeof(Void), state))
> }
>
> protected def _computeTypes(ReceiveMessage expression,
> ITypeComputationState state) {
>
> /* here i call addLocalToCurrentScope(XvariableDeclaration,
> state) and pass vd field */
>
>
>
>
>
>
> }
> }
>
>
>
> it works till here but if i want remove the field vd from my grammar ,
> how can i do?
> i try to create my XVariableDeclaration in _computeTypes(ReceiveMessage)
> and then call addLocalTocurrentScope but it don't work..
Hi Andrea,
your receive message could either extend JvmIdentifiableElement and you
put that one directly into the local var table, or you could make the
name part of your receive message an JvmIdentifiableElement. Does that
make sense?
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.02999 seconds