Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » scoping problem(the scoping is not called because the current model is null)
scoping problem [message #897488] Tue, 24 July 2012 09:28 Go to next message
stefan tudose is currently offline stefan tudoseFriend
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 Very Happy
Re: scoping problem [message #897563 is a reply to message #897488] Tue, 24 July 2012 14:00 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
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
Re: scoping problem [message #897785 is a reply to message #897563] Wed, 25 July 2012 09:01 Go to previous messageGo to next message
stefan tudose is currently offline stefan tudoseFriend
Messages: 12
Registered: July 2012
Junior Member
Hi Sebastian,
Thanks for your answer.
I've already tried to enforce the creation of an CcmAttributeVariable, but it doesn't work better. I mean the scope is still not called when I want to start with a CcmAttributeVariable. I see that, when I am in the CcmAttributeVariable and the scoping should be called, the contentAssistContext.getCurrentModel() is null. It should be a CcmAttributeVariable, shouldn't it?
Could this be because I use bactrack=true and, at this point, we still can't decide wether the expression is a "CheckTmValue" or an "CheckTmValueList"?
What docs should I refer to? Can you be more specific?
Thank you!
Stefan
Re: scoping problem [message #898839 is a reply to message #897785] Fri, 27 July 2012 21:33 Go to previous messageGo to next message
Benjamin Schwertfeger is currently offline Benjamin SchwertfegerFriend
Messages: 53
Registered: July 2009
Member
Hi Stefan,
I had a similar problem in my DSL. I'll add a snippet for my solution. I tried to define attributes and allow subsequent attributes depending on the type of the attribute.

The problem is the different context in content assist and runtime parser.

1. The runtime parser:
For the runtime parser the model is parsed completely and all EObjects are created before scoping is called with the direct container. You can access the container and all references but the one, which is currently scoped.

2. The UI-Parser (content assist)
The UI-Parser have to work even if the container is not initialized yet. The context will be the next container above the current reference where an assignment was done. Without assignment no element is created, even if you add actions.

In a project in the past we assigned the keyword, i.e. attr='attr' in your case, in a similar case just to create the context.

The current solution to use alternating references to distinguish the to possible context in the scope provider and avoid cyclic resolution.

Perhaps this can help you, or you find a better solution, which I can adapt.

Regards,
Benjamin


ParameterDefinition: ParameterAssignment;

ParameterAssignment :
parameter=[conftypes::Feature|FQN] '=' (value=Literal|'{' values += ParameterAssignment2*'}')
;

ParameterAssignment2 :
parameter=[conftypes::Feature|FQN] '=' (value=Literal|'{' values += ParameterAssignment*'}')
;
Re: scoping problem [message #899487 is a reply to message #898839] Wed, 01 August 2012 07:11 Go to previous message
stefan tudose is currently offline stefan tudoseFriend
Messages: 12
Registered: July 2012
Junior Member
Ok, thanks Benjamin, I'll try using your solution.
Previous Topic:The path is unmapped after changing Directorylayout
Next Topic:weird encoding problem with properties-files
Goto Forum:
  


Current Time: Thu Apr 18 03:32:52 GMT 2024

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

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

Back to the top