Home » Modeling » TMF (Xtext) » implicit variable declaration in dsl editor with xbase
implicit variable declaration in dsl editor with xbase [message #1060462] |
Fri, 24 May 2013 20:14 |
andrea rossi Messages: 23 Registered: April 2013 |
Junior Member |
|
|
Hi , this is a part of my dsl grammar :
.....
ReceiveMessage returns xbase::XExpression :
{ReceiveMessage} 'receive message' name=ValidID 'do' body= XBlockExpression
;
Message returns xbase::XExpression:
SendMessage | ReceiveMessage
;
XExpressionInsideBlock returns xbase::XExpression:
XVariableDeclaration | XExpression | Message;
....
In my dsl editor i can write this :
...
behaviour HelloBehaviour is CyclicBehaviour
{ receive message msg
do {
val i = 5
msg.getContent() // error no declaration of msg
}
}
I can't write msg.getContent() in the receive message body because i haven't declare msg.
I would like to write "receive message msg" in dsl editor and can use msg like a variable in the body of receive message.
(e.g implicit declaration : ACLMessage msg )
How can i do it?
Thank you...
[Updated on: Sat, 25 May 2013 23:06] Report message to a moderator
|
|
|
Re: implicit variable declaration in dsl editor with xbase [message #1060528 is a reply to message #1060462] |
Sun, 26 May 2013 09:02 |
|
On 05/24/2013 10:14 PM, andrea rossi wrote:
> Hi , this is a part of my dsl grammar :
> ....
> ReceiveMessage returns xbase::XExpression : {ReceiveMessage} 'receive
> message' name=ValidID 'do' body= XBlockExpression
> ;
>
> Message returns xbase::XExpression: SendMessage | ReceiveMessage
> ;
>
> XExpressionInsideBlock returns xbase::XExpression:
> XVariableDeclaration | XExpression | Message;
> ...
>
>
>
> In my dsl editor i can write this :
> ..
> behaviour HelloBehaviour is CyclicBehaviour { receive message msg do {
> val i = 5
> msg.getContent() // error no declaration of msg }
> }
>
>
> I can't write msg.getContent() in the receive message body because i
> haven't declare msg.
> I would like can write "receive message msg" in dsl editor and can use
> msg like a variable in the body of receive message.
> (e.g implicit declaration : ACLMessage msg )
>
you should write the JvmModelInferrer accordingly, e.g., for receive
message (by the way, do not use terminal symbols with spaces: 'receive'
'message', instead of 'receive message') you can infer a method with
parameter 'msg' and with the appropriate type, and the the XExpression
after 'do' can access msg (once you associated the XExpression to the
body of the inferred method).
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: implicit variable declaration in dsl editor with xbase [message #1060598 is a reply to message #1060528] |
Mon, 27 May 2013 08:55 |
andrea rossi Messages: 23 Registered: April 2013 |
Junior Member |
|
|
Thank you for your advices...
I don't use JvmModelInferrer for receive message but extend XBaseCompiler
This is a part of my class that extend XbaseCompiler :
override protected doInternalToJavaStatement(XExpression expr, ITreeAppendable it, boolean isReferenced) {
.....
switch expr {
ReceiveMessage : {
if (expr.filter != null){
newLine
append ('''MessageTemplate mt = null; ''')
newLine
append ('''mt = ''' )
append('''«createTemplate(expr.filter as Expression,it)» ;''')
newLine
append('''
jade.lang.acl.ACLMessage msg = myAgent.receive(mt); ''')
}
else { newLine append('''jade.lang.acl.ACLMessage msg = myAgent.receive()''')}
newLine
append('''if (msg!=null){ ''')
increaseIndentation()
doInternalToJavaStatement(expr.body, it, isReferenced)
append('''} ''')
decreaseIndentation()
newLine
append('''else { block(); }''')
}
....
I call doInternalToJavaStatement method and pass ReceiveMessage body.
How i can set implicit variable declaration here?
thank you in advance
[Updated on: Mon, 27 May 2013 08:59] Report message to a moderator
|
|
|
Re: implicit variable declaration in dsl editor with xbase [message #1060628 is a reply to message #1060598] |
Mon, 27 May 2013 11:31 |
|
Try to use JvmModelInferrer whenever possible since you'll get for free
correct scoping!
You can have a customized XbaseCompiler to deal with your custom
XExpression (if you have any) or invoke XbaseCompiler directly if you
want to generate code before and after the actual XExpression's
translation... but for the rest, try to use JvmModelInferrer
I don't know whether this http://www.rcp-vision.com/?p=4089 might help you
Lore
On 05/27/2013 10:55 AM, andrea rossi wrote:
> Thank you for you advices...
> I don't use JvmModelInferrer for receive message but extend XBaseCompiler
> This is a part of my class that extend XbaseCompiler :
>
>
>
> override protected doInternalToJavaStatement(XExpression expr,
> ITreeAppendable it, boolean isReferenced) {
>
> ....
>
> switch expr {
>
> ReceiveMessage : {
>
> if (expr.filter != null){
> newLine
> append ('''MessageTemplate mt = null; ''')
> newLine append ('''mt = ''' )
> append('''«createTemplate(expr.filter as
> Expression,it)» ;''')
> newLine append('''
> jade.lang.acl.ACLMessage msg = myAgent.receive(mt);
> ''')
> }
> else { newLine append('''jade.lang.acl.ACLMessage msg =
> myAgent.receive()''')}
> newLine append('''if (msg!=null){ ''')
> increaseIndentation()
> doInternalToJavaStatement(expr.body, it, isReferenced)
> append('''} ''') decreaseIndentation()
> newLine append('''else { block(); }''')
>
> }
>
> ...
>
>
>
>
> I call doInternalToJavaStatement method and pass ReceiveMessage body.
> How can set implicit variable declaration here?
>
>
> thank you in advance
>
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| | | | | |
Re: implicit variable declaration in dsl editor with xbase [message #1061499 is a reply to message #1061485] |
Sat, 01 June 2013 07:40 |
|
ReceiveMessage returns xbase::XExpression : {ReceiveMessage} 'receive
message' name=ValidID 'do' body= XBlockExpression
I would map it as follows
ReceiveMessage -> Java method
name -> Java method's parameter (you have to give it a type)
body -> Java method's body
this way
receive message msg do {
val i = 5
msg.getContent() // error no declaration of msg }
}
msg can be automatically accessed...
of course I do not know all the details and semantics of your language,
so mine's just a guess...
Lorenzo
On 05/31/2013 11:22 PM, andrea rossi wrote:
> Hi,
>
> this i part of my JvmModelInferrer :
> def dispatch void infer(Model element,
> IJvmDeclaredTypeAcceptor acceptor, boolean
> isPrelinkingPhase) {
> for (a : element.elements) {
> switch a {
> AbstractBehaviour : {
> switch a {
> SimpleBehaviour : {
>
> acceptor.accept(a.toClass(a.fullyQualifiedName)).initializeLater [
> superTypes +=
> a.newTypeRef('jade.core.behaviours.'+ a.typeSB.toString)
> members += a.toConstructor[
> documentation = '''...'''
> parameters += toParameter("agent",
> newTypeRef(a, 'jade.core.Agent'))
> body = [
> append('''
> super(agent);
> ''')
> ]
> ]
> members +=
> a.toMethod("action",a.newTypeRef(Void::TYPE))[
> body = a.body
> ]
> ]
>
> }
> }
> }
>
>
>
>
> i translate each simpleBehaviour in a java class e i inferr one
> method(action).
> The body of this method is body of behaviour(i.e XblockExpression) and
> it can contain xbase expression or my custom xbase expression.
>
> How can i map ReceviMessage in the right way?(it must been contained in
> the action body)
> any little example?
>
>
> Hi Christian how can i fix the scoping of my custom xbase expression?
> thank you
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Goto Forum:
Current Time: Fri Apr 26 03:28:38 GMT 2024
Powered by FUDForum. Page generated in 0.03709 seconds
|