Scope for starting element [message #922871] |
Tue, 25 September 2012 12:16 |
Gaspar Din 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 |
|
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 |
Gaspar Din 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
Regards
Gaspar
|
|
|
|
Re: Scope for starting element [message #924901 is a reply to message #924869] |
Thu, 27 September 2012 08:15 |
Gaspar Din 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.
or
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
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06329 seconds