Questions about scoping [message #987333] |
Mon, 26 November 2012 03:30  |
Eclipse User |
|
|
|
Hello,
I'm trying to provide scoping for some references in my model. I have a specific case where providing scoping becomes tricking.
Suppose that we have the following piece of grammar:
Ecu returns Ecu:
'ecu' name=EString '{'
'components:' componentRef+=ComponentPrototypeInstRef ("," componentRef+=ComponentPrototypeInstRef)* ';'
'}';
ComponentPrototypeInstRef returns ComponentPrototypeInstRef:
(context+=[ComponentPrototype]'.')* target=[ComponentPrototype]
;
I would like to provide a scoping rule for the 'context' and 'target' references. However, two problems occur:
1) If the user types 'components:' and ask for content assist (Ctrl+space) my scoping rule is not invoked but however, the full list of existing ComponentPrototype is still displayed. I understood that the problem here is that because no instance of a ComponentPrototypeInstRef is created at that time, so my scoping rule cannot be called. However, I don't understand how Xtext is then able to supply the list. How can I override that behavior ?
2) If you look at the ComponentPrototypeInstRef, the 'context' reference is in fact a list of references. This is because a ComponentPrototype can be deeply nested (in the ComponentType, look at the attached picture to understand the domain model). So there, I need to provide scoping for this reference but I need to know which element in the list of 'context' I have to provide scoping for, otherwise I'll end up in a cyclic resolution of lazy links.
I however have one requirement (which is pretty strict): I cannot change the domain model! The Xtext syntax is based on a domain model and not the opposite.
Attachment: EMFmodel.PNG
(Size: 7.09KB, Downloaded 270 times)
|
|
|
|
|
|
|
|
Re: Questions about scoping [message #1067566 is a reply to message #1007381] |
Tue, 09 July 2013 07:20  |
Eclipse User |
|
|
|
If you look at other projects where component chaining is done you'll see a specific pattern which creates a simple object when there is no '.' and then wraps that current object in a new object if there is a dot, and repeats the wrapping for more dots.
This example is not tested but should be somehting like this:
ComponentPrototypeInstRef returns ComponentPrototypeInstRef:
{ComponentPrototypeInstRef}
target=[ComponentPrototype]
( {ComponentPrototypeInstRef.context=current} '.' target=[ComponentPrototype] )*
;
So if there is no '.' then you simply have a ComponentPrototypeInstRef with target referencing a ComponentPrototype, and a null context.
And if you add a '.' with another prototype, you get a ComponentPrototypeInstRef with context referencing that 'current' simple ComponentPrototypeInstRef as the head of the chain and a target referencing the ComponentPrototype after the dot.
In the scoping function the elements in scope for the target reference are the elements of the context ComponentPrototypeInstRef.
See xbase modules as an example.
Note that 'context' as a name of a reference is confusing as it may not be the same context object in your scoping function.
|
|
|
Powered by
FUDForum. Page generated in 0.04485 seconds