格式化生产规则,不包含任何类型

时间:2018-03-12 21:00:33

标签: formatting xtext

有时,在定义Xtext语法时,我定义了没有impred类型的生产规则。

例如,在定义表达式语言时,括号可用于处理运算符优先级,但不必是元模型中的类型。

例如,语法波纹可用于定义以下两个布尔表达式“true&& false || true”和“true&&(false || true)”。

def dispatch void format(And and, extension IFormattableDocument document) {

}

在xtext中,格式化是通过将EMF模型元素转移到格式化方法来完成的,例如:

colorKey = list("Species"=list("setosa"="gold","versicolor"="silver","virginica"="red"))

但是在Lit的第三个生成规则(括号)的情况下,没有任何类型是故意定义的,这阻止我调度到这个句法元素。 因此,我无法找到一种方法来为我的语法部分定义格式规则。

如何在这样的上下文中为括号定义格式规则?

1 个答案:

答案 0 :(得分:0)

我认为你必须在更高层次上这样做。

@Inject extension DomainmodelGrammarAccess

def dispatch void format(Operation operation, extension IFormattableDocument document) {

    operation.allRegionsFor.keywords(XParenthesizedExpressionAccess.leftParenthesisKeyword_0).forEach [
        append[noSpace]
    ]
    operation.allRegionsFor.keywords(XParenthesizedExpressionAccess.rightParenthesisKeyword_2).forEach [
        prepend[noSpace]
    ]