|
|
|
Re: How to access fields of rules within a grammar [message #1740932 is a reply to message #1740931] |
Fri, 19 August 2016 20:12   |
|
Hi,
i still cannot follow you
attributes+=AbstractAttribute*;
AbstractAttribute:
Attribute | CombinedAttribute;
Attribute:
'attribute' name=ID '(' minValue=INT ',' maxValue=INT ')'
value=INT;
CombinedAttribute:
'combinedAttribute' name=ID '(' minValue=INT ',' maxValue=INT ')'
value=Expression;
Expression:
Addition;
Addition returns Expression:
Multiplication ({Addition.left=current} '+' right=Multiplication)*;
Multiplication returns Expression:
Primary ({Multiplication.left=current} '*' right=Primary)*;
Primary returns Expression:
NumberLiteral |
AttributeRef |
'(' Addition ')';
AttributeRef:
attribute=[Attribute] "." part=AttributePart; //if you can reference value only why not simply leave off the .xxx part
enum AttributePart:
maxValu | minValue | value;
NumberLiteral:
value=INT;
Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: How to access fields of rules within a grammar [message #1746948 is a reply to message #1740907] |
Tue, 08 November 2016 00:24   |
Karsten Wilken Messages: 59 Registered: August 2016 |
Member |
|
|
Hello again,
if I use
AttributeRef:
attribute=[Attribute] "." part=AttributePart;
I get a "Couldn't resolve reference to Entity xyz".
Could you give me a hint to the possible reasons?
The relevant parts of the dsl are the following:
'game' name = QualifiedName '('
elements+=Entity*
')';
Entity:
Character | Attribute | //others-not relevant for the example
;
Character:
'character' name = QualifiedName '('
properties += Property*
')'
;
Property:
'attributeProperty' value = [Attribute] | //others not relevant
;
AttributeRef:
attribute=[Attribute] '.' part=AttributePart
;
enum AttributePart:
attrName | attrValue | attrMinValue | attrMaxValue
;
The example DSL in orion web editor:
game testGame (
attribute agility ( range[0, 20] )
character goblin (
attributeProperty testGame.agility <-- last entered part with auto suggestion
)
)
The editor responds with the following error message: "Couldn't resolve reference to Entity 'testGame'.
Am I overlooking some mistake in the DSL or is it something i messed up or forgot in the setup/config?
[Updated on: Tue, 08 November 2016 00:25] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: How to access fields of rules within a grammar [message #1747326 is a reply to message #1747322] |
Sat, 12 November 2016 07:52   |
|
well the bindings may "destroy" the play together of xtext name providers. especially regarding xbase.
and well xbase has another problem which the content assist in the web currently does not check
the name "xxx.yyy" is not serializable as in ID but as FQN only thus it should be filtered by content assist but seems not to be done in web.
xxx=[YYY] is short for xxx=[YYY|ID] which means "parse an ID for the cross ref to a YYY" so testGame.something will not be parseable by that
i have created https://github.com/eclipse/xtext-core/issues/175
as a workaround
package org.xtext.example.mydsl4.web
import com.google.common.base.Predicate
import com.google.inject.Inject
import org.eclipse.emf.ecore.EClass
import org.eclipse.xtext.CrossReference
import org.eclipse.xtext.GrammarUtil
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import org.eclipse.xtext.resource.IEObjectDescription
import org.eclipse.xtext.xtext.CurrentTypeFinder
import org.xtext.example.mydsl4.myDsl.MyDslPackage
class MyDslIdeContentProposalProvider extends XbaseIdeContentProposalProvider {
@Inject extension CurrentTypeFinder
static val FILTER = new MyFilter
override protected getCrossrefFilter(CrossReference reference, ContentAssistContext context) {
val type = findCurrentTypeAfter(reference)
val ereference = GrammarUtil.getReference(reference, type as EClass)
if (MyDslPackage.Literals.PROPERTY__VALUE == ereference) {
println("xxxx")
return FILTER
}
super.getCrossrefFilter(reference, context)
}
}
class MyFilter implements Predicate<IEObjectDescription> {
override apply(IEObjectDescription input) {
return input.name.segmentCount == 1
}
}
override Class<? extends IdeContentProposalProvider> bindIdeContentProposalProvider() {
MyDslIdeContentProposalProvider
}
Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05427 seconds