Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » (no subject)
(no subject) [message #673404] Mon, 23 May 2011 13:49
Lex  is currently offline Lex Friend
Messages: 4
Registered: May 2011
Junior Member
Parsing it as a separate PropertyDeclaration is the way I did it initially but then my model didn't really match the semantics of my language.

int var1;
int var2;

and

int var1, var2;

Should be semantically equivalent and produce the same model. The second is merely a short cut for the first. Anytime I want to get a list of all properties of a class I would have to do some computation, I couldn't just return a list of properties. Also, any tools generated by Xtext wouldn't work as intended when displaying the list of properties in the outline or some other UI code. I would have to add special cases any place where a list of properties should be displayed.

Furthermore, it's my understanding that the point of a model is to represent the semantics of your language, not its syntax. The declaration shortcut is not semantically interesting and I would rather it didn't make it into my model.

I have not completely ruled this out though, depending on how hard it is going to be to make this work the right way I may just go back to having my model represent the syntax instead of the semantics at least for that portion of the language.

I have made some progress doing it the way I described in my original post. Xtext will not let you valueconvert an EObject but surprisingly they let you valueconvert an EJavaObject. I was able to change my code like this:

Model:
'model' name=ID '{'
(propertyTypes+=[DataType] properties+=Property (',' properties+=Property)* ';')*
'}'

Property returns ecore::EJavaObject: ID;

By using ecore::EJavaObject the Value Converter is actually triggered. And has the following code:

public Object toValue(String name, INode node) {
Property prop = SorceFactory.eINSTANCE.createProperty();
DataType type = SorceFactory.eINSTANCE.createDataType();

EObject o = null;
INode n = node;
while ((n = n.getPreviousSibling()) != null) {
o = n.getGrammarElement();
if (o instanceof org.eclipse.xtext.impl.CrossReferenceImpl) {
break;
}
}
type.setName(n.getText());

prop.setName(name);
prop.setType(type);

return prop;
}

The problem is that I couldn't figure out how to go from a CrossReference to a DataType (I create a new DataType but I don't think that's what I want to do). All I could get is a TypeRef but I don't understand well enough how all of the cross referencing works to be able to navigate from the reference to the actual object being referenced.

So, my questions are:

How can I get the DataType object from a CrossReference?

Are there any downsides to implementing this feature as I have done above?

Are there any benefits or downsides to implementing it as Alex suggested vs the method above?






Btw, here is what Xtext.log() in the unit tests looks like for a sample object:

input:

type Money {}
type Str {}
type Color {}
model Foo {
Str crackers, cheese;
}


output:

Sorce {
cref Element elements [
0: CustomType {
attr EString name 'Money'
}
1: CustomType {
attr EString name 'Str'
}
2: CustomType {
attr EString name 'Color'
}
3: Model {
attr EString name 'Foo'
ref DataType propertyTypes [
0: CustomType@//@elements.1
]
attr EJavaObject properties [
0: Property {
attr EString name 'crackers'
ref DataType type ref: DataType@(resource null)
}
1: Property {
attr EString name 'cheese'
ref DataType type ref: DataType@(resource null)
}
]
}
]
}
Previous Topic:(no subject)
Next Topic:Type var, var, var;
Goto Forum:
  


Current Time: Fri Apr 26 05:44:20 GMT 2024

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

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

Back to the top