我正在使用AbstractFormatter2和xtext 2.9.2
我想将评论放在特定栏目中
我的语法看起来像这样
terminal SL_COMMENT : '*' !('\n'|'\r')* ('\r'? '\n')?;
到目前为止,我尝试在评论之前添加多个空格,但这不起作用
def dispatch void format(Model model, extension IFormattableDocument document) {
SL_COMMENTRule.prepend[space " "]
model.getEnte.format;
model.getMapset.format;
}
任何人都可以指导我如何格式化评论,然后如何将它们放在特定列中
答案 0 :(得分:0)
评论格式由commentreplacers
完成因此以下内容应该起作用
override createCommentReplacer(IComment comment) {
val EObject grammarElement = comment.getGrammarElement();
if (grammarElement instanceof AbstractRule) {
val String ruleName = grammarElement.getName();
if (ruleName.startsWith("SL")) {
if (comment.getLineRegions().get(0).getIndentation().getLength() > 0) {
return new SinglelineDocCommentReplacer(comment, "//") {
override configureWhitespace(WhitespaceReplacer leading, WhitespaceReplacer trailing) {
leading.getFormatting().space = " ";
}
};
} else {
return new SinglelineCodeCommentReplacer(comment, "//") {
override configureWhitespace(WhitespaceReplacer leading, WhitespaceReplacer trailing) {
leading.getFormatting().space = " ";
}
}
}
}
}
super.createCommentReplacer(comment)
}