Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » content assist(use content assist instead of cross reference)
content assist [message #759230] Sun, 27 November 2011 21:22 Go to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
hello all,

is it possible to use content-assist stubs to let editor give references to another rule elements? like instead of cross-reference in grammar level.

reason is, i am doing xtext for Prolog-like language and am enforced sometimes to write anti-elegant rules, just because they are working! i am thinking to resort to content assist to fill the gap! does it make sense?

thanks a lot.
Mokhtar
Re: content assist [message #759317 is a reply to message #759230] Mon, 28 November 2011 11:12 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Of course this is possible, but you'd have to rewrite (or re-integrate) a lot of functionality that Xtext provides out-of-the-box when using cross-references proper. And of course, you'd then only have something purely textual in your parsed model instead of a real reference so you have to implement the de-referencing yourself as well. What exactly prohibits you from using cross-references in the those "anti-elegant rules".

Re: content assist [message #759524 is a reply to message #759317] Mon, 28 November 2011 23:26 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
Thank you Meinte,

many things prohibit me from using cross-references:
1- rules to be referenced are part of other rules and not single model elements
2- my grammar inherits another one which both dont use common.Terminal i.e ref = [Rule1] wont work cuz ID is not there implicitly. if explicitly like ref = [Rule1|MyID] i got also some problems.
so it is Shocked Shocked

thank you,
Mokhtar
Re: content assist [message #759527 is a reply to message #759524] Tue, 29 November 2011 00:38 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
Dear Meinte, dear all,
given this dsl:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
elements+=Element*;

Element:
Food|Person;
Food:
categ = FoodCateg 'food' name = ID
;
Person:
'person' name = ID ('likes' likes=[FoodCateg])?
;
FoodCateg:
'category' name=ID
;
and this first program written withby:

category nuts food coco
person mokhtar likes nuts

Do you know why is the second statment invalid? i tried coco.nuts as suggested by quick fix but still point to coco as where EOF
Thank you for helping,
Mokhtar
Re: content assist [message #759528 is a reply to message #759527] Tue, 29 November 2011 00:46 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
No Message Body
Re: content assist [message #759557 is a reply to message #759527] Tue, 29 November 2011 07:43 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the fully qualified name of nuts is indeed coco.nuts, as the category is a child of Food and uses the parent's name as a "prefix". However, your cross reference allows only simple names (ref=[Type] is short for ref=[Type|ID], meaning use an ID to reference an object of type Type). However, "coco.nuts" is not an ID as it contains a dot.

There are several options.
-Use the simple name fragment, i.e. don't use qualified names
-Introduce a QualifiedName-rule (see domain model example or Xbase grammar) and reference via qualified name
-adapt the qualified name of FoodCateg returning a simple name
-adapt scoping

*improve the grammar/metamodel, making it more common sense like
It is not quite intuitive that the category is a child of the food. I would expect the category to be defined elsewhere and the food to reference the category it belongs to (or define a category and have *all* its possible food as children).
As it is now, you would define the category nuts over and over again.

Alex
Re: content assist [message #759565 is a reply to message #759557] Tue, 29 November 2011 08:37 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Alexander Nittka wrote on Tue, 29 November 2011 08:43

As it is now, you would define the category nuts over and over again.

...which is plainly nuts! Very Happy (Sorry, couldn't resist Wink)


Re: content assist [message #759747 is a reply to message #759565] Tue, 29 November 2011 20:13 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
Thank you Alex, i introduced this example just to describe my problem. It has no intuition, just a demo. my current DSL work would not fit here and you would hate me if i ask you to understand it Wink
i will investigate what you wrote me. i just couldn't resist to thank you before
Best,
Mokhtar
Re: content assist [message #759780 is a reply to message #759557] Wed, 30 November 2011 01:18 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
Thanks again for helping but could you answer the following:
you wrote:

Quote:
There are several options.
-Use the simple name fragment, i.e. don't use qualified names
-Introduce a QualifiedName-rule (see domain model example or Xbase grammar) and reference via qualified name
-adapt the qualified name of FoodCaeg returning a simple name
-adapt scoping

q1) do you mean like alex likes nuts instead of alex likes coco.nuts? it didnt work unless i make ('likes' likes=[FoodCateg|QName])
q2)what do you mean by "adapt the qualified name of FoodCateg returning a simple name"? can you give me an example?
q3)scoping?!? i have no idea how
q4) is it true what i discovered that one must give a feature with the name 'name = ID' in order the qulified name-rule trick to work?

thanks alot!
Mokhtar

[Updated on: Wed, 30 November 2011 01:21]

Report message to a moderator

Re: content assist [message #759800 is a reply to message #759780] Wed, 30 November 2011 06:53 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
q1) is already answered, [FoodCateg] is equivalent to [FootCateg|ID] and coco.nuts is not an ID.
q2) see the documentation on naming, search for IQualifiedNameProvider and check out the DefaultDeclarativeQualifiedNameProvder
q3) see the documentation, search for scoping, there are hundreds of threads here with scoping questions
q4) see the documentation, the feature name "name" has a special meaning for naming elements

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Previous Topic:RCP product for Xtext
Next Topic:Postorder traversal of AST during validation.
Goto Forum:
  


Current Time: Sat Apr 04 23:02:14 GMT 2020

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

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

Back to the top