I am working on a DSL wherein I am supposed to call Java Functions I have written. How can they be called in XText Grammar definition rules ?

Example Sample.xtext Data: 'Data'':' (objectRules += ObjectRule)+ //Call to Java Function here ; I am writng the grammar and I want to invoke Java Function to perform further processing like pasting a block of code when the Rule is encountered.

有帮助吗?

解决方案

Please refer to the documentation on Xbase if you want to use Java from your Xtext languages.

The pattern would be something like this:

grammar org.acme.MyDsl with org.eclipse.xtext.xbase.Xbase
generate ..
MyConcept:
  operation=ID '(' ')' body = XBlockExpression
;

This would allow things like

myOperation() {
  System.out.println("")
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top