How to access fields of rules within a grammar [message #1740907] |
Fri, 19 August 2016 12:53  |
Eclipse User |
|
|
|
until now I couldn't find a related topic via google or topics in this forum. (maybe I haven't found the right keywords yet)
Ok,
my goal is to declare a method body within the grammar and to use other "rules" or rather classes and access fields but somehow I can't figure out how to make it work.
I need to create a "combinedAttribute" where the combination of the value depends on a combination of other "attributes".
Therefor I need access to the fields of attribute within the grammar itself. As far as I saw examples most of the time real access and "java stuff" isn't done within the grammar.
Attribute:
'attribute' name = ID '(' minValue = INT ',' maxValue = INT ')'
value = INT
CombinedAttribute:
'combinedAttribute' name = ID '(' minValue = INT ',' maxValue = INT ')'
<< missing stuff to calculate the value >>
My first instinct went to "Attribute.value" but didn't work or maybe I just don't get the correct syntax for it.
My second attempt was a params list of attributes that are combinated and I only specify that within the math expression I want the leafs to be of the type Attribute.
No good idea and xtext was mad because thanks to the recursion Attribute could be a supertype in that expression.
Nevermind my attempts. Any idea how I can get it to work? My idea in Java is pretty clear:
getValue(Attribute a, Attribute b, Attribute c) {
return (a.value + b.value / c.value);
}
The math expression should be any combination of basic math terms (+ , - , * , / ).
That part is easy and well explained in tutorials.
I can't figure out how to access fields within the grammar and how to reference them.
Secondary: The web editor i created seems to not notice the types or references at all. I'm not sure if it is a related issue or subject for a new topic.
To state an example for this issue:
I tried to provide a list of attributes that are part of the combinate attribute.
something like attribute agitity [...]
within the combinate attribute the attribute named "agility" could be choosen from the suggestions but the grammar or rather the editor couldn't solve the type.
But this part is not as important as the first part.
Thanks for your help and suggestions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.13580 seconds