Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1863849] |
Fri, 01 March 2024 10:19 |
Kaan B. Y. Messages: 15 Registered: June 2023 |
Junior Member |
|
|
Hello,
I have implemented a custom scope provider for my DSL.
In a nutshell:
@InjectLogger
Logger logger;
@Override
IScope getScope(EObject context, EReference ref) {
logger.info("Providing scope for " + context);
if (context instanceof SpecificObject1) {
// Dispatch type-specific scopeFor
logger.info("Dispatching scoper for SpecificObject1");
scopeFor(context, ref);
}
if (context instanceof SpecificObject2) {
// Dispatch type-specific scopeFor
}
// ...
// If none of the if blocks match, use the default scope provider
super.getScope(context, ref);
}
// ...
dispatch IScope scopeFor(SpecificObject1 context, EReference ref) {
// Provide special scope for specific object
// val scope = ...
logger.info("Returning custom scope for SpecificObject1 instance");
return scope;
}
Now, I have a situation where the scopeFor method for SpecificObject1 is dispatched without ever entering the getScope method defined by the IScopeProvider interface. This has become evident to me due to the missing log message, to be more specific, there is a case where "Returning custom scope for SpecificObject1 instance" is printed, but "Dispatching scoper for SpecificObject1" doesn't show up at all.
How is this possible? I have thought of the getScope method of the IScopeProvider interface as the "entry point" for all scoping.
Thanks in advance and regards
K.
[Updated on: Fri, 01 March 2024 11:53] Report message to a moderator
|
|
|
|
|
Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1863897 is a reply to message #1863896] |
Mon, 04 March 2024 14:05 |
Kaan B. Y. Messages: 15 Registered: June 2023 |
Junior Member |
|
|
Let me also provide some more context regarding the DSL:
The language itself is very simple, it consists of field and section declarations. A section can have multiple supertypes.
SectionDeclaration:
"section" Symbol
SectionFragment
;
fragment SectionFragment*:
(":" supertype=InheritanceChain)?
("{"
(elements+=FieldDeclaration)*
"}")?
;
FieldDeclaration:
Symbol
":" type=RootExpression
("=" assignment=RootExpression)?
;
InheritanceChain is a Rust-like supertype declaration (Section1 + Section2 + Section3...)
RootExpression is the root rule for expressions, symbols, literals, etc.
When a field assignment is scoped, it should also contain the fields of the supertypes of the section it is contained in.
This means
section MySection {
foo: Int = 10
}
section MySectionChild : MySection {
bar: Int = foo + 10
}
should be linked correctly.
How should the assignment in a FieldDeclaration be scoped? Should I check if SectionDeclaration occurs as an eContainer for the respective FieldDeclaration?
[Updated on: Mon, 04 March 2024 14:07] Report message to a moderator
|
|
|
|
|
|
Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1865256 is a reply to message #1864027] |
Mon, 29 April 2024 15:05 |
Kaan B. Y. Messages: 15 Registered: June 2023 |
Junior Member |
|
|
Hello,
I had to upgrade Xtext inbetween but I am back on topic again.
Let me restate my question:
As far as I have understood it, when Xtext needs to scope an EObject, it provides the assigned scope provider with the respective EObject. My question is, is there some kind of internal "scope inheritance" done by Xtext?
Consider the example from my previous message:
section MySection {
foo: Int = 10
}
section MySectionChild : MySection {
bar: Int = foo + 10
}
If I scope in MySection for MySectionChild, should I explicitly "append" that scope to the scope of the RootExpression ('foo + 10') in the assignment of bar, or is the scope of MySectionChild already in the scope of the bar FieldDeclaration, because MySectionChild is the eContainer of bar?
Thanks in advance for your answer.
[Updated on: Mon, 29 April 2024 15:05] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06364 seconds