set type of custom xbase expression [message #1111189] |
Tue, 17 September 2013 19:17  |
Eclipse User |
|
|
|
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 17:20   |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04111 seconds