Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » set type of custom xbase expression
set type of custom xbase expression [message #1111189] Tue, 17 September 2013 23:17 Go to next message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
Hi,

I would like to have an expression that returns a certain type

This is a part of my grammar :
Entity :  
  'entity' name = ValidID 
 (body=XBlockExpression)
;

XExpressionInsideBlock returns xbase::XExpression:
  XVariableDeclaration | XExpression |  MyAgent
;

MyAgent is my custom xbase expression and I would like to use it on the right of the assignment operator.
I extended XbaseCompiler and XbaseTypeComputer.
This is a part of my XbaseTypeComputer :


class EntityTypeComputer extends XbaseTypeComputer {

	override computeTypes(XExpression expression, ITypeComputationState state) {
		 if ((expression instanceof MyAgent)){
		    _computeTypes(expression as MyAgent,state)}
		 else {
		    super.computeTypes(expression, state)
		}
	}
protected def _computeTypes(MyAgent expression, ITypeComputationState state) {
		state.acceptActualType(getTypeForName(typeof(Agent), state))
	}


I tried to write this in my dsl editor but it doesn't work :
entity MyEntity
{ var Agent ag = myAgent }

the errors are : "no viable alternative at input 'myAgent'" and "Type cannot be derived"

what is my mistake?

Thank you in advance

Re: set type of custom xbase expression [message #1111874 is a reply to message #1111189] Wed, 18 September 2013 21:20 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1368
Registered: July 2009
Senior Member
On 18/09/2013 01:17, andrea rossi wrote:
> Hi,
> I would like to have an expression that returns a certain type
>
> This is a part of my grammar :
> Entity : 'entity' name = ValidID (body=XBlockExpression)
> ;
>
> XExpressionInsideBlock returns xbase::XExpression:
> XVariableDeclaration | XExpression | MyAgent
> ;
>
> MyAgent is my custom xbase expression and I would like to use it on the
> right of the assignment operator.
> I extended XbaseCompiler and XbaseTypeComputer. This is a part of my
> XbaseTypeComputer :
>
>
> class EntityTypeComputer extends XbaseTypeComputer {
>
> override computeTypes(XExpression expression, ITypeComputationState
> state) {
> if ((expression instanceof MyAgent)){
> _computeTypes(expression as MyAgent,state)}
> else {
> super.computeTypes(expression, state)
> }
> }
> protected def _computeTypes(MyAgent expression, ITypeComputationState
> state) {
> state.acceptActualType(getTypeForName(typeof(Agent), state))
> }
>
>
> I tried to write this in my dsl editor but it doesn't work :
> entity MyEntity
> { var Agent ag = myAgent }
>
> the errors are : "no viable alternative at input 'myAgent'" and "Type
> cannot be derived"
>
> what is my mistake?

This sounds like a problem during parsing doesn't it?

I suppose you want 'myAgent' to be parsed by MyAgent rule, but it isn't,
is it?

what's the shape of MyAgent rule?

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
Re: set type of custom xbase expression [message #1112260 is a reply to message #1111874] Thu, 19 September 2013 10:22 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
Hi,

this is myAgent rule :

MyAgent returns xbase::XExpression : 
	{MyAgent}'myAgent' name = ValidID
;


If I write this in my dsl editor works :
entity MyEntity
 { var Integer i = 1
   myAgent agent
 } 

but if I write this doesn't work:
entity MyEntity
 { var Agent ag = myAgent agent} 


I would like to have an expression I can use in Xblock that returns a certain type and than the expression can be used in the right part of the assignment.

How can I do this?


[Updated on: Thu, 19 September 2013 10:23]

Report message to a moderator

Re: set type of custom xbase expression [message #1112490 is a reply to message #1112260] Thu, 19 September 2013 19:45 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1368
Registered: July 2009
Senior Member
On 19/09/2013 12:22, andrea rossi wrote:
> Hi,
>
> this is myAgent rule :
>
> MyAgent returns xbase::XExpression : {MyAgent}'myAgent' name = ValidID
> ;
>
>
> If i write this in my dsl editor work :
>
> entity MyEntity
> { var Integer i = 1
> myAgent agent
> }
> but if I write this doesn't work:
> entity MyEntity
> { var Agent ag = myAgent agent}
>
> I would like to have an expression I can use in Xblock that returns a
> certain type and than the expression can be used in the right part of
> the assignment.
>
> How can I do this?

mh... have you tried to make your agent rule first in
XExpressionInsideBlock?

I mean

XExpressionInsideBlock returns xbase::XExpression:
MyAgent | XVariableDeclaration | XExpression
;


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
Re: set type of custom xbase expression [message #1113047 is a reply to message #1112490] Fri, 20 September 2013 15:07 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
Hi,

yes I tried but it doesn't works....
Re: set type of custom xbase expression [message #1113647 is a reply to message #1113047] Sat, 21 September 2013 13:03 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1368
Registered: July 2009
Senior Member
On 20/09/2013 17:07, andrea rossi wrote:
> Hi,
>
> yes I tried but it doesn't works....

You may want to try to customize XPrimaryExpression instead of
XExpressionInsideBlock...

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
Re: set type of custom xbase expression [message #1133353 is a reply to message #1113647] Fri, 11 October 2013 20:20 Go to previous message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
Sorry for the delay of my reply, I would like to thank you for your help. It works

[Updated on: Fri, 11 October 2013 20:21]

Report message to a moderator

Previous Topic:Question about cross-linking and creation of instances
Next Topic:Disappearing arguments? (Outline)
Goto Forum:
  


Current Time: Thu Oct 23 08:47:08 GMT 2014

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

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