FilteringScope: how to use correctly?

Hi, I'm missing a hint in the help system for using Scopes of type "FilteringScope". I'm guessing that one should define a derived class that extends FilteringScope, and overrides the isExcluded(node) method. Or should one directly use an instance of FilteringScope? Which scope should be provided to the constructor, the current node's scope?

Thank you upfront.

3 comments

Hi Janrichter!

Could you tell me where you are facing FilteringScope? I first thought that was one option for reference scope in concept constraints. I checked it, and no, it's not the case. However, obviously wherever you are expected to return a scope you are free to use FilteringScope. And I can help with what it's about.

 

The answers to all your questions are outside of "scope" (pun definitely intended) of FilteringScope semantics. I mean, all FilteringScope does is transforms the given scope in a way, that something from the original scope is excluded. It does that by means of isExcluded() method.

By directly using new FilteringScope(baseScope) you would get a scope that is identical to baseScope, because the implementation of isExcluded() is just 'return false'. So, yes it makes perfect sense to subclass FilteringScope and define isExcluded(). Regarding what you pass to the constructor, again, it really doesn't matter. It depends on your situation.

You can think of classes like FilteringScopes as scope combinators, which make it more convenient to construct scopes. E.g.

new FilteringScope(new NamedElementsScope(...my node sequence...)) {
  isExluded(node) {
     !node.name.endsWith("foo");
  }
}

Here you build your scope out of small building blocks, like NamedElementsScope and FilteringScope

If you described your problem in more specific terms I could give some more hints.

 

 

0

Thank you, your hint was helpful to create a filtering scope.

I’m building a DSL for describing systems and their hierarchical interconnections with input and output variables (ports if you like) and internal state variables. There are connection equations that allow you to connect outputs to inputs. I’m using the ScopeProvider interface to reduce the scope of visible variables to those declared at the given hierarchy level. I override the getScope() methods within the appropriate concepts as needed. That works pretty well. No FilteringScopes needed there.

Now in connection equations, the current of the DSL allows me to include state variables in the equation. That’s illegal in the language. The scope of visible variables should be provided by the relevant ScopeProvider. It should contain input, state, and output variables.

At the level of connection equations, I intend to use FilteringScope to narrow down scope from (in, state, out) to (in, out) for variables, overriding the isExcluded() method as you indicate below. First question: is this also a situation where you would use FilteringScope?

Secondly, I'm realizing that the parentScope is null at the level of connection equations concept. This should not be the case. Should not MPS go up in the node hierarchy until it finds a scope provider? How could this process be disrupted, except by a ScopeProvider that provides nothing – empty scope? I’m scanning my concept hierarchy but don’t have such a concept that would be ScopeProvider but not at least pass parentScope by default. I'll be grateful for hints to debugging scopes, including how to print the contents of scopes to stderr.

Thanks a lot!

0

Hi

As for the usage you describe, if the language is structured in a way that the construct for connection equations by default sees all variables (both ports and state) than yes, FilteringScope seems ok. However, another option would be to construct the scope only out of those port variables in the first place, so that no filtering is needed. If I saw language structure I could say more definitively.

As for parent scope, yes, it's strange. I think you should be getting EmptyScope in the worst case. So you try to get parent scope in your scope provider and getting null, right? Can you show the code that does that? I mean your ScopeProvider.getScope()

0

Please sign in to leave a comment.