scoping problem [message #897488] |
Tue, 24 July 2012 09:28 |
stefan tudose Messages: 12 Registered: July 2012 |
Junior Member |
|
|
Hello,
I have the following grammar:
//////////////////////////////////////////////////////////////
Expression returns Expression:
Check | Operator ;
Operator returns Operator:
{And}
'(' leftExpression=Expression ')'
'AND'
'(' rightExpression=Expression ')'
|
{Or}
'(' leftExpression=Expression ')'
'OR'
'(' rightExpression=Expression ')'
;
Check returns Expression:
CheckTmValue | CheckTmValueList
;
CheckTmValue returns CheckTmValue:
varRef=Variable
operator=OperatorCheckValue
value=DataValue
;
CheckTmValueList returns CheckTmValueList:
varRef=Variable
operator=OperatorCheckListValue
'{' ListValues+=DataValue ( "," ListValues+=DataValue)* '}'
;
Variable returns Variable:
CcmAttributeVariable
;
CcmAttributeVariable returns CcmAttributeVariable:
'attr'
referencedCcmAttribute=[baseidl::AttributeDef]
;
enum OperatorCheckListValue returns OperatorCheckListValue:
same = 'same' | inside = 'inside' | notInside = 'notInside' | sameOrder = 'sameOrder' | inAnyOrder = 'inAnyOrder' | atLeast = 'atLeast' | atLeastInAnyOrder = 'atLeastInAnyOrder' | in = 'in' | atMost = 'atMost';
enum OperatorCheckValue returns OperatorCheckValue:
equal = '==' | different = '!=' | lessThan = '<' | greaterThan = '>' | lessThanOrEqual = '<=' | greaterThanOrEqual = '>=';
DataValue returns dspData::DataValue:
IntegerValue | DoubleValue;
IntegerValue returns dspData::IntegerValue:
{dspData::IntegerValue}
value=EInt;
DoubleValue returns dspData::DoubleValue:
{dspData::DoubleValue}
value=EDouble
;
EInt returns ecore::EInt:
'-'? INT;
EDouble returns ecore::EDouble:
'-'? INT? '.' INT (('E'|'e') '-'? INT)?;
//////////////////////////////////////////////////////////////
I have enabled backtracking.
What I would like to do: every time the user has to give a referencedCcmAttribute, he can chose between different proposed elements. I used the scoping for this (in the getScope(EObject context, EReference reference) I manually load a model and return the desired elements).
The problem : When I start with an operator, everything works fine (E.g. I start with a '(', then I have 'attr' and then all the attributes I want). But if I want to give directly a Check, it doesn't work (e.g. I start with 'attr' then xtext doesn't give me any choice for the attribute).
I have found that, in this case, it doesn't even enter my getScoping method, because the model is null (in class AbstractJavaBasedContentProposalProvide, in method lookupCrossReference). But I don't understand what should I do to get it working and what is wrong with my grammar...
Please help me
|
|
|
Re: scoping problem [message #897563 is a reply to message #897488] |
Tue, 24 July 2012 14:00 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
You may want to add an action before the 'attr' keyword in order to
enforce the creation of an instance. Otherwise you'll get the container
passed into your scope provider. That should be the easiest way to
achieve what you describe.
CcmAttributeVariable returns CcmAttributeVariable:
{CcmAttributeVariable}
'attr'
referencedCcmAttribute=[baseidl::AttributeDef]
;
Please refer to the docs for details on actions and the like.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 24.07.12 11:28, schrieb stefan tudose:
> Hello,
> I have the following grammar:
>
> //////////////////////////////////////////////////////////////
> Expression returns Expression:
> Check | Operator ;
>
> Operator returns Operator:
> {And}
> '(' leftExpression=Expression ')'
> 'AND'
> '(' rightExpression=Expression ')'
> |
> {Or}
> '(' leftExpression=Expression ')'
> 'OR'
> '(' rightExpression=Expression ')'
> ;
>
> Check returns Expression:
> CheckTmValue | CheckTmValueList ;
>
> CheckTmValue returns CheckTmValue:
> varRef=Variable
> operator=OperatorCheckValue
> value=DataValue
> ;
>
> CheckTmValueList returns CheckTmValueList:
> varRef=Variable
> operator=OperatorCheckListValue
> '{' ListValues+=DataValue ( "," ListValues+=DataValue)* '}' ;
>
> Variable returns Variable:
> CcmAttributeVariable
> ;
>
> CcmAttributeVariable returns CcmAttributeVariable:
> 'attr'
> referencedCcmAttribute=[baseidl::AttributeDef]
> ;
>
> enum OperatorCheckListValue returns OperatorCheckListValue:
> same = 'same' | inside = 'inside' | notInside = 'notInside' |
> sameOrder = 'sameOrder' | inAnyOrder = 'inAnyOrder' | atLeast =
> 'atLeast' | atLeastInAnyOrder = 'atLeastInAnyOrder' | in = 'in' | atMost
> = 'atMost';
>
> enum OperatorCheckValue returns OperatorCheckValue:
> equal = '==' | different = '!=' | lessThan = '<' | greaterThan =
> '>' | lessThanOrEqual = '<=' | greaterThanOrEqual = '>=';
>
> DataValue returns dspData::DataValue:
> IntegerValue | DoubleValue;
>
> IntegerValue returns dspData::IntegerValue:
> {dspData::IntegerValue}
> value=EInt;
>
> DoubleValue returns dspData::DoubleValue:
> {dspData::DoubleValue}
> value=EDouble
> ;
>
> EInt returns ecore::EInt:
> '-'? INT;
>
> EDouble returns ecore::EDouble:
> '-'? INT? '.' INT (('E'|'e') '-'? INT)?;
>
> //////////////////////////////////////////////////////////////
>
> I have enabled backtracking.
> What I would like to do: every time the user has to give a
> referencedCcmAttribute, he can chose between different proposed
> elements. I used the scoping for this (in the getScope(EObject context,
> EReference reference) I manually load a model and return the desired
> elements).
> The problem : When I start with an operator, everything works fine (E.g.
> I start with a '(', then I have 'attr' and then all the attributes I
> want). But if I want to give directly a Check, it doesn't work (e.g. I
> start with 'attr' then xtext doesn't give me any choice for the attribute).
>
> I have found that, in this case, it doesn't even enter my getScoping
> method, because the model is null (in class
> AbstractJavaBasedContentProposalProvide, in method
> lookupCrossReference). But I don't understand what should I do to get it
> working and what is wrong with my grammar...
>
> Please help me :d
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01636 seconds