Scope for starting element [message #922871] |
Tue, 25 September 2012 08:16  |
Eclipse User |
|
|
|
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 #924839 is a reply to message #924798] |
Thu, 27 September 2012 03:03   |
Eclipse User |
|
|
|
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 04:15   |
Eclipse User |
|
|
|
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 04:17] by Moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 1.02699 seconds