| Scope for starting element [message #922871] |
Tue, 25 September 2012 08: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 #924839 is a reply to message #924798] |
Thu, 27 September 2012 03: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 04: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 04:17] Report message to a moderator
|
|
|
|
| Re: Scope for starting element [message #924937 is a reply to message #924913] |
Thu, 27 September 2012 04:49   |
Gaspar Din 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 #924995 is a reply to message #924981] |
Thu, 27 September 2012 05:47   |
Gaspar Din 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02440 seconds