Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » QualifiedName to a computed scope(Scoping semantics)
QualifiedName to a computed scope [message #701329] Mon, 25 July 2011 01:13 Go to next message
Moritz   is currently offline Moritz Friend
Messages: 22
Registered: July 2011
Junior Member
Hi,

I am currently stuck to support the access of features (here: ports) of an entity's type. I already found many helpful sources about scoping, mostly in the forum and the docu - thanks! - but don't know where to look further now.

A short description, please find my questions below:

Lets say I have entities of a certain type, and these types provide ports. As the ports are features of the type, I have to create the scope for them manually when I want to access ports from within the context of an entity.

When I want to access these ports by a qualified name, I cannot do it the same way as in the tutorial, because the ports are not automatically part of an entity's scope (as far as I understood).

Here is a reduced example:

Domainmodel:
	(nativeTypes += NativeType)*
	(entities += Entity)*
;

Type: NativeType | Entity;

NativeType:
	'native' (name = ID) ('(' (ports += Port) (',' ports += Port)* ')')
;

Port: name = ID;

Entity:
	'entity' (name = ID) (':' type = [NativeType])? '{' 
		(subentities += Entity)*
		(assignments += Assignment)*
	'}'
;

Assignment:
	(ePath += [Entity] '.')* (port = [Port]) '=' INT
;


public class EntityDslScopeProvider extends AbstractDeclarativeScopeProvider {
	IScope scope_Assignment_port(Assignment context, EReference reference) {
		return getPortScope((Entity)context.eContainer());
	}
	IScope scope_Assignment_port(Entity context, EReference reference) {
		return getPortScope(context);
	}
	
	/** Computes the scope of accessible ports for an entity */
	IScope getPortScope(Entity entity) {
		IScope scope = IScope.NULLSCOPE;
		// Compute the outer scope of ports first
		if (entity.eContainer() instanceof Entity) {
			scope = getPortScope((Entity)entity.eContainer());
		}
		return Scopes.scopeFor(entity.getType().getPorts(), scope);
	}
}


And a picture that shows a possible use case and the current state:
index.php/fa/3457/0/
[update: Please forget about the first comment seen in this picture]
Note that the qualified names are not working yet (i.e. in blockADD.A, blockADD does note influences the following port name yet)


  1. The scoping methods compute the visible ports from within an entity. Is this the straightforward way to provide attributes that are not automatically part of the scope, or is it too cumbersome?

  2. The expression (ePath += [Entity] '.')* (port = [Port]) shall obviously do something similar to (port = [Port|QualifiedName]).
    My approach was to compute the scope of the last part, the [Port], with the information of the ePath in the method
    IScope scope_Assignment_port(Assignment context, EReference reference)
    but this context is only provided for finished Assignments. Also the
    public void completeAssignment_Port(EObject model, ...
    does not provide ePath.
    There must be a (better) way to compute the scope for features with a qualified name. The QualifiedNameProvider does only compute the composition of the names, so maybe there are other scope provider that I can use to provide this (simple) naming scheme? How can I use them in a project?

  3. I understood that contentassist+validation can give you better error messages than just scoping, but besides that I currently can't do it either way, I think scoping is the right decision here. How can I extend the default error message "Couldn't resolve reference to Port 'A'." with something like "only ports 'X' and 'Y' are defined here."?


The first part of the chapter about scoping[1] is mostly about global scopes and imports, but maybe I misunderstood something there. If anyone has an idea how to continue with this problem or if there is a better way to do it, I would greatly appreciate it.

Moritz


[1]help.eclipse.org/helios/topic/org.eclipse.xtext.doc/help/scoping.html?path=67_4_5_1_0#DeclarativeScoping

[Updated on: Mon, 25 July 2011 01:44]

Report message to a moderator

Re: QualifiedName to a computed scope [message #717507 is a reply to message #701329] Sun, 21 August 2011 04:12 Go to previous message
Moritz   is currently offline Moritz Friend
Messages: 22
Registered: July 2011
Junior Member
I am sorry if my question was to detailed or sounded arrogating.

For those interested, I finally found the solution in these threads:

http://www.eclipse.org/forums/index.php/t/223017/
http://www.eclipse.org/forums/index.php/t/173546/ >> http://www.eclipse.org/forums/index.php/t/173562/
http://www.eclipse.org/forums/index.php/t/172683/
(no subject) [message #717509 is a reply to message #701329] Sun, 21 August 2011 04:12 Go to previous message
Moritz   is currently offline Moritz Friend
Messages: 22
Registered: July 2011
Junior Member
No Message Body

[Updated on: Sun, 21 August 2011 12:17]

Report message to a moderator

(no subject) [message #717510 is a reply to message #701329] Sun, 21 August 2011 04:12 Go to previous message
Moritz   is currently offline Moritz Friend
Messages: 22
Registered: July 2011
Junior Member
No Message Body

[Updated on: Sun, 21 August 2011 12:17]

Report message to a moderator

(no subject) [message #717515 is a reply to message #701329] Sun, 21 August 2011 04:12 Go to previous message
Moritz   is currently offline Moritz Friend
Messages: 22
Registered: July 2011
Junior Member
No Message Body

[Updated on: Sun, 21 August 2011 12:18]

Report message to a moderator

(no subject) [message #717521 is a reply to message #701329] Sun, 21 August 2011 04:12 Go to previous message
Moritz   is currently offline Moritz Friend
Messages: 22
Registered: July 2011
Junior Member
No Message Body

[Updated on: Sun, 21 August 2011 12:18]

Report message to a moderator

(no subject) [message #717530 is a reply to message #701329] Sun, 21 August 2011 04:12 Go to previous message
Moritz   is currently offline Moritz Friend
Messages: 22
Registered: July 2011
Junior Member
No Message Body

[Updated on: Sun, 21 August 2011 12:18]

Report message to a moderator

Previous Topic:a question about linking
Next Topic:Absolute file path
Goto Forum:
  


Current Time: Fri Apr 19 08:30:54 GMT 2024

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

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

Back to the top