|
Re: set type of custom xbase expression [message #1111874 is a reply to message #1111189] |
Wed, 18 September 2013 21:20 |
|
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
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: set type of custom xbase expression [message #1112260 is a reply to message #1111874] |
Thu, 19 September 2013 10:22 |
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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03047 seconds