Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scope for starting element
Scope for starting element [message #922871] Tue, 25 September 2012 12:16 Go to next message
Gaspar DinFriend
Messages: 21
Registered: September 2012
Junior Member
Hi,

my grammar starts with an element like
AllAnimals: Horse | Dog | Fish | Bird;

to edit different types.
Nevertheless, sometimes the sub type is known in advance, e.g. the editor should be limited to the 'Dog' element.
Is it possible to tell the editor to change the possible editable types to sub elements only?
Can this be achieved with the scope provider?

Thanks
Gaspar
Re: Scope for starting element [message #924798 is a reply to message #922871] Thu, 27 September 2012 06:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

Is this decision static (a certain place in the grammar) then you could introduce a special parsing rule for that.
you are mentioning the scopeprovider
this is for cross refs only. you did not post anything of the rest of your grammar.
so it is really hard to give any advice.
it would be nice if you could post a complete (please simplify it) grammar and an example model

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope for starting element [message #924839 is a reply to message #924798] Thu, 27 September 2012 07:03 Go to previous messageGo to next message
Gaspar DinFriend
Messages: 21
Registered: September 2012
Junior Member
Hi Christian,

a simplified Xtext describing the problem:
AllAnimals: Horse | Dog | Fish | Bird;

Horse: {Horse} "Horse" "(" weight=INT "," height=INT ")";
Dog: SmallDog | BigDog;
SmallDog: {SmallDog} "SmallDog" "(" weight=INT "," name=STRING ")"
BigDog: {BigDog} "BigDog" "(" description=STRING "," age=INT ")"
Fish: {Fish} "Fish" "(" maxDepth=INT "," lenght=INT "," name=STRING ")"
Bird: {Bird} "Bird" "(" color=STRING ")"

With this definition, its possible to edit s.th. like:
Horse (100, 150)
SmallDog (10, "Hektor")
Bird ("blue")

But there are cases where the type is restricted, e.g. "Dog" (and not "AllAnimals").
How can I start the editor then to allow only dog like entries, i.e. for example:
SmallDog (5, "Hasso")
BigDog ("nice and friendly", 5)

but not
Fish (200, 20, "Nemo")

Regards
Gaspar
Re: Scope for starting element [message #924869 is a reply to message #924839] Thu, 27 September 2012 07:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi you still have no place in your grammar where you want to use your
Dog and/or AllAnimals

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope for starting element [message #924901 is a reply to message #924869] Thu, 27 September 2012 08:15 Go to previous messageGo to next message
Gaspar DinFriend
Messages: 21
Registered: September 2012
Junior Member
Hi,

sorry but my descrpition was not clear enough.
My simplified xtext definition:
grammar de.example.xtext.Animals with org.eclipse.xtext.common.Terminals

generate animals "h**p://www.example.de/xtext/Animals"

AllAnimals: Horse | Dog | Fish | Bird;

Horse: {Horse} "Horse" "(" weight=INT "," height=INT ")";
Dog: SmallDog | BigDog;
SmallDog: {SmallDog} "SmallDog" "(" weight=INT "," name=STRING ")";
BigDog: {BigDog} "BigDog" "(" description=STRING "," age=INT ")";
Fish: {Fish} "Fish" "(" maxDepth=INT "," lenght=INT "," name=STRING ")";
Bird: {Bird} "Bird" "(" color=STRING ")";

With this definition, it is possible (and wanted) to edit a single line only.
E.g.
Horse (100, 150)

or
SmallDog (10, "Hektor")

But sometimes it has to be restricted. In the usecase the sub type ("Dog" or "Fish") may be known.
I could write a validator to check for the supported type. But then, I have to adjust proposal, quickfix etc., too.
And the final grammar is a lot more complex.
It would be more easy to somehow (how?) change the starting behaviour to start with "Dog" instead of a super type "AllAnimals".
Is this possible?

Regards
Gaspar

[Updated on: Thu, 27 September 2012 08:17]

Report message to a moderator

Re: Scope for starting element [message #924913 is a reply to message #924901] Thu, 27 September 2012 08:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi I still want know if you have a place like
DogWorld: "test" dog=AllAnimals. What is the context/criteria for the
"sometimes" you do not want all animals

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope for starting element [message #924937 is a reply to message #924913] Thu, 27 September 2012 08:49 Go to previous messageGo to next message
Gaspar DinFriend
Messages: 21
Registered: September 2012
Junior Member
Hi,
there is no other place like
DogWorld: "test" dog=AllAnimals.
(For now, there are no needs to consider this (code generation does not matter for this).)

The context criteria is only known at runtime (before starting the editor).
At runtime, the program determines a (sub) type (i.e. "AllAnimals" or "Dog" or "SmallDog" etc.).
The user then may open the editor to edit/modify this (sub) type.
So, in some cases, the user must not be allowed to enter a wrong kind of animal/type.

Thanks
Gaspar
Re: Scope for starting element [message #924954 is a reply to message #924937] Thu, 27 September 2012 09:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi guess then it is hard to do this.
You could try to adopt content assist.
But you would need checks anyway

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope for starting element [message #924981 is a reply to message #924954] Thu, 27 September 2012 09:28 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
You could try to overwrite MyDslAntlrParser#getDefaultRuleName or
#doParse or something to leverage some contextual information. Most
likely you'll have to customize XtextResource#update(int, int, String)
and #doLoad, too.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 27.09.12 11:01, schrieb Christian Dietrich:
> Hi guess then it is hard to do this.
> You could try to adopt content assist.
> But you would need checks anyway
>
Re: Scope for starting element [message #924995 is a reply to message #924981] Thu, 27 September 2012 09:47 Go to previous messageGo to next message
Gaspar DinFriend
Messages: 21
Registered: September 2012
Junior Member
Hi Sebastian,

this sounds promising.
A first try in overwriting MyDslAntlrParser#getDefaultRuleName
worked fine and exposed error messages for wrong types.
Only the code completion still knows about the "wrong" types
and still makes wrong suggestions.

Thanks
Gaspar
Re: Scope for starting element [message #925113 is a reply to message #924995] Thu, 27 September 2012 11:27 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Gaspar,

please try to hook into
MyDslParser.getFollowElements(AbstractInternalContentAssistParser)
in your UI plugin.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 27.09.12 11:47, schrieb Gaspar Din:
> Hi Sebastian,
>
> this sounds promising.
> A first try in overwriting MyDslAntlrParser#getDefaultRuleName
> worked fine and exposed error messages for wrong types.
> Only the code completion still knows about the "wrong" types
> and still makes wrong suggestions.
>
> Thanks
> Gaspar
Re: Scope for starting element [message #925126 is a reply to message #924995] Thu, 27 September 2012 11:52 Go to previous message
Gaspar DinFriend
Messages: 21
Registered: September 2012
Junior Member
Hi Sebastian,

yes, that's it.
Overriding the ContentAssistParser allows switching to the right type proposal.

Thank you
Gaspar
Previous Topic:Where is spell checking configured?
Next Topic:NPE in serializer
Goto Forum:
  


Current Time: Tue Apr 16 12:25:39 GMT 2024

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

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

Back to the top