我如何使用编写的 Xtend 生成器代码在 Xtext 中生成?

How can I generate in Xtext with the the Xtend Generator code as it was written?

我在 Xtext 中定义了这个语法,当使用 Xtend 生成代码时,我想获得编写的选择表达式。

所以当像x = "abc"这样的选择表达式|| (y="pqr" && z = "lmn") 是用该语法编写的,生成器代码将表达式准备为字符串,如 "x = "abc" || (y="pqr" && z = "lmn")”。这怎么可能?

Queries:
    (query+=Query)*;
Query:
    'get' 'patient' selection = Selection ('view' view = View)? ';'
;
View:
    'examination'| 'bill' | 'illness' | 'prescription'
;
Selection:
    OrSelection | {Selection} '*'
;   
OrSelection returns Selection:
    AndSelection ({OrSelection.left=current} "||" right=AndSelection)*  
;   
AndSelection returns Selection:
    PrimarySelection ({AndSelection.left=current} "&&" right=PrimarySelection)*  
;
PrimarySelection returns Selection:
    "(" Selection ")"
| Literal
;
Literal returns Selection:
   {Literal}  attribute = Attribute '=' value = Value 
;
Attribute:
   name = ID
;
Value:
    name = STRING
;

您可以使用 NodeModelUtils 获取 EObjectINode,然后向节点询问其文本

NodeModelUtils.findActualNodeFor(obj).getText()

NodeModelUtils.getNode(obj).getText()

后者可能包括评论等