-
|
I have a Grammar (languim 3.1) as follows (modified hello-world): with a formatter as follows: protected override format(node: AstNode): void {
if (ast.isGroup(node)) {
const formatter = this.getNodeFormatter(node);
const start = formatter.keyword('group');
const bracesOpen = formatter.keyword('{');
const bracesClose = formatter.keyword('}');
start.prepend(Formatting.newLines(3));
formatter.interior(bracesOpen, bracesClose).prepend(Formatting.indent());
bracesOpen.prepend(Formatting.newLine());
bracesClose.prepend(Formatting.newLine());
formatter.property('name').surround(Formatting.oneSpace());
} else if (ast.isModel(node)) {
const formatter = this.getNodeFormatter(node);
const nodes = formatter.nodes(...node.groups);
nodes.prepend(Formatting.noIndent());
}
}This works as expected: a model is formatted like in the following example: However, when changing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Hey @goto40, at least in this case, you run into conflicting formattings. On one hand you have |
Beta Was this translation helpful? Give feedback.
Hey @goto40,
at least in this case, you run into conflicting formattings. On one hand you have
formatter.property('name').surround(Formatting.oneSpace()), which expects that betweengroup hellothere is exactly one space. On the other hand you havestart.append(Formatting.newLines(3)), which expects that betweengroup hellothere are three new lines. Since thesurround(Formatting.oneSpace())call comes last, it receives precedence.