Strange scoping behaviour [message #764679] |
Mon, 12 December 2011 11:50  |
Eclipse User |
|
|
|
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 #764984 is a reply to message #764745] |
Tue, 13 December 2011 03:20  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03601 seconds