Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Strange scoping behaviour
Strange scoping behaviour [message #764679] Mon, 12 December 2011 16:50 Go to next message
Steffen Schuette is currently offline Steffen SchuetteFriend
Messages: 26
Registered: August 2010
Junior Member
Dear community,

I'm using xText (xText 2.0.0) for quite a while now but obviously there are still some back spots in my understanding (or there is a bug:-).

I've implemented a xText grammar for specifying JSON schemas in the Orderly syntax (well actually I used the code from https://github.com/crealytics/orderly_json_xtext). Heres the code:

Type:
  (IntegerType |
  FloatType |
  ObjectType |
  SimpleArrayType)
  ;


IntegerType:
  {IntegerType} 'integer';
  
FloatType:
  {FloatType} 'float';
  

ObjectType:
  {ObjectType} 'object' '{' 
    (fields+=Field)* 
  '}' ;

Field:
   name=ID':'type=Type;

SimpleArrayType:
  'array'  '[' 
    type=Type
  ']' range=IntRange?;

DataFlow:
	name=ID':'type=Type;



This works fine. DataFlow is the root class describing a type. For example, take a look at the following structure specification created with the DSL:

schedule : object { //dataflow called schedule specifying a complex object
	name : string
	entries: array[
		object 
		{
			start:integer
					duration:integer
		}
	]
}


However, now I want to navigate in this tree to specify certain attributes. I thought this is easy but I cannot manage to get the scoping right. Here is my DSL code:


FieldPath:
	{FieldPath}
	'.'field=[Field] path=FieldPath?
;


DataFlowPath:
	{DataFlowPath}
	dataFlow=[DataFlow] path=FieldPath?
;



For the scoping I implemented the following (not finished, yet):

//This works fine
public IScope scope_DataFlowPath_dataFlow(EntityData ed, EReference ref) {
    ArrayList<EObject> flows = new ArrayList<EObject>();
    flows.add(ed.getFlowType());
    return Scopes.scopeFor(flows);
}
		
//This method does strange things
public IScope scope_FieldPath_field(DataFlowPath fp, EReference ref) {
    Type t = fp.getDataFlow().getType();
    if (t instanceof ObjectType)
    {
        return Scopes.scopeFor(((ObjectType)t).getFields());
    }		
			
    return null;
}


But my problem here is that I can get into an infinit scoping situation.e.g. this is valid:

schedule.name.name

How can that be? Name is no complex object and can therefore not contain another type called name. I don't get it



Thank you so much,

Steffen
Re: Strange scoping behaviour [message #764745 is a reply to message #764679] Mon, 12 December 2011 19:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

a complete reproducable grammar would have been helpful. never the less: what happens is absoulutely correct!
you may be missing a

public IScope scope_FieldPath_field(FieldPath fp, EReference ref) {
}

method.

never the less have a look at http://dslmeinte.wordpress.com/2010/08/16/path-expressions-in-entity-models/
to get an idea what to do

result may be something like (untested)

	public IScope scope_FieldPath_field(FieldPath fp, EReference ref) {
	    EObject parent = fp.eContainer();
	    if (parent instanceof DataFlowPath) {
	    	return scope_FieldPath_field((DataFlowPath)parent, ref);
	    } else if (parent instanceof FieldPath) {
	    	Type t = ((FieldPath)parent).getField().getType();
	    	if (t instanceof ObjectType)
		    {
		        return Scopes.scopeFor(((ObjectType)t).getFields());
		    }
	    }
				
	    return IScope.NULLSCOPE;
	}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 12 December 2011 19:37]

Report message to a moderator

Re: Strange scoping behaviour [message #764984 is a reply to message #764745] Tue, 13 December 2011 08:20 Go to previous message
Steffen Schuette is currently offline Steffen SchuetteFriend
Messages: 26
Registered: August 2010
Junior Member
Hi,

thank you very much for the fast response and the link to the tutorial. Now it works.
I already had such a method (any I also understand why it is required) but I used return null instead of returning the Nullscope. And that made the difference. Didn't know that.

Best,

Steffen
Previous Topic:Same function, different signature -> ContentAssist
Next Topic:log info from FeatureCallCompiler
Goto Forum:
  


Current Time: Fri Apr 26 08:06:32 GMT 2024

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

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

Back to the top