Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » scope of custom xbase expression
scope of custom xbase expression [message #1076142] Tue, 30 July 2013 19:51 Go to next message
andrea rossi is currently offline andrea rossiFriend
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 #1076744 is a reply to message #1076142] Wed, 31 July 2013 20:12 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Andrea,

you have to customize XbaseTypeComputer.computeTypes(XExpression,
ITypeComputationState) and add the handling for your custom expressions.
See also _computeTypes(XVariableDeclaration, ITypeComputationState) to
learn how to add something to the scope.

Hope that helps,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.07.13 21:51, schrieb andrea rossi:
> 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 scope of my xbase expressions?
> Any suggestion?example?
>
> thank you in advance
>
>
Re: scope of custom xbase expression [message #1078968 is a reply to message #1076744] Sat, 03 August 2013 22:16 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossiFriend
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 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
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
Re: scope of custom xbase expression [message #1084297 is a reply to message #1081401] Sun, 11 August 2013 09:13 Go to previous message
andrea rossi is currently offline andrea rossiFriend
Messages: 23
Registered: April 2013
Junior Member
Hi Sebastian

I think JvmIdentifiableElement doesn't work in my context..
I use vd field as XVariableDeclaration in ReceiveMessage and it can work well for my purposes..
I wondered if I can create an XVaribaleDeclaration in _computeTypes(ReceiveMessage) and then call addLocalTocurrentScope with it(instead of using vd field)

Thank you in advance
Previous Topic:SemanticSequencer generator: naming clash with ecore packages
Next Topic:xtext import of models from other projects buggy?
Goto Forum:
  


Current Time: Sat Apr 27 01:14:30 GMT 2024

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

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

Back to the top