[英]Xtext Custom DSL formatting
In my DSL I have () for a lot of stuff for example if conditions and some declarations such as block(a;b;c;d;); 在我的DSL中,例如条件和一些声明(例如block(a; b; c; d;);
In my configureFormatting function I do this in the following order: 在我的configureFormatting函数中,我按以下顺序进行操作:
for (Pair<Keyword, Keyword> pair : grammarAccess.findKeywordPairs("(", ")"))
{
c.setNoSpace().after(pair.getFirst());
c.setNoSpace().before(pair.getSecond());
}
c.setIndentation(block.getLeftParenthesisKeyword(),block.getRightParenthesisKeyword());
c.setLinewrap().after(block.getLeftParenthesisKeyword());
c.setLinewrap().before(block.getRightParenthesisKeyword());
Expected is: 预期为:
block (
int z;
int a;
int y;
);
if (a = 1)
Actual Result: 实际结果:
block (int z;
int a;
int y;);
if (a = 1)
you see the actual result because within the for-loop you set explicitly that you don't want spaces after the first '(' and before the ')'. 您会看到实际结果,因为在for循环中您明确设置了您不希望在第一个'('和')'之后使用空格。
Try the following: 请尝试以下操作:
for (Pair<Keyword, Keyword> pair : grammarAccess.findKeywordPairs("(", ")")) {
c.setIndentation(pair.getFirst(), pair.getSecond()); // indent between ( )
c.setLinewrap().after(pair.getFirst()); // linewrap after (
c.setLinewrap().before(pair.getSecond()); // linewrap before )
c.setNoSpace().after(pair.getSecond()); // no space after )
}
Hope that helps! 希望有帮助!
Well I have figured it out. 好吧,我已经弄清楚了。 It was simple. 很简单。 I made the following: 我做了以下事情:
for (Pair<Keyword, Keyword> pair : grammarAccess.findKeywordPairs("(", ")"))
{
if(pair.getFirst() != block.getLeftParenthesisKeyword())
c.setNoSpace().after(pair.getFirst());
if(pair.getSecond() != block.getRightParenthesisKeyword())
c.setNoSpace().before(pair.getSecond());
}
c.setIndentation(block.getLeftParenthesisKeyword(),block.getRightParenthesisKeyword());
c.setLinewrap().after(block.getLeftParenthesisKeyword());
c.setLinewrap().before(block.getRightParenthesisKeyword());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.