Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.0] Problem referencing sub entities
[Xtext 2.0] Problem referencing sub entities [message #695050] Sun, 10 July 2011 21:42 Go to next message
Sebastian Herold is currently offline Sebastian HeroldFriend
Messages: 5
Registered: July 2011
Junior Member
Hi,

I was experimenting with Xtext and got stuck in referencing sub entities. Here my simple grammar:
Model:
	(classes+=Class)+
	(refs+=Reference)*	
;

Class:
	'class' name=ID '{'
		(fields+=Field)*
	'}'
;

Field:
	'field' name=ID
;

Reference:
	'set' name=ID from=[Field]
;

Now, I started with a short exmaple model:
class Test {
	field name
	field code
	field size
}

But I had problems to define a Reference-rule. I typed:
set Foo 

but got no suggestion for the referencing field in the editor. Then, I typed:
set Foo name

and got a quick-fix to change "name" to "Test.name". I confirmed, but now I have a syntax error in line:
set Foo Test.name

Is there any other solution to reference sub-entities?

[Updated on: Sun, 10 July 2011 21:45]

Report message to a moderator

Re: [Xtext 2.0] Problem referencing sub entities [message #695053 is a reply to message #695050] Sun, 10 July 2011 21:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you are stumbling over qualified names. by default these are built like ...grandparentname.parentname.name.
in your case for a field Test.name, Test.code and Test.size
so you can change this default behaviour by registering a custom IQualifiedNameProvider (e.g subclass of DefaultDeclarativeQualifiedNameProvider)
or to allow the qualified name in your grammar:

Reference:
	'set' name=ID from=[Field|FQN]
;
FQN: ID ("." ID)*;


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtext 2.0] Problem referencing sub entities [message #695205 is a reply to message #695053] Mon, 11 July 2011 09:30 Go to previous messageGo to next message
Sebastian Herold is currently offline Sebastian HeroldFriend
Messages: 5
Registered: July 2011
Junior Member
Thanks for the fast response. It solved my problem. Would be great to have it in the docs.

Regards,
Sebastian

[Updated on: Mon, 11 July 2011 10:02]

Report message to a moderator

Re: [Xtext 2.0] Problem referencing sub entities [message #695211 is a reply to message #695205] Mon, 11 July 2011 09:43 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it is actually in the docs (Scoping Chapter) but rather implicit than explicit.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Toggle "Link with editor" in Outline
Next Topic:Unordered group problem
Goto Forum:
  


Current Time: Fri Apr 26 15:55:29 GMT 2024

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

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

Back to the top