mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
[tracing] handle indent differently
This commit is contained in:
parent
bcde648c21
commit
0cb38c5f4c
6 changed files with 46 additions and 11 deletions
|
@ -45,6 +45,19 @@ class GeneratorNodeTest {
|
|||
}'''.toString, result.traceRegion.toString)
|
||||
}
|
||||
|
||||
@Test def void testEmptyIndent() {
|
||||
val root = loc(0)
|
||||
var node = root.trace.append("Hallo").appendNewLine;
|
||||
node.indent;
|
||||
node.append("noindent").appendNewLine
|
||||
|
||||
val processor = new GeneratorNodeProcessor()
|
||||
Assert.assertEquals('''
|
||||
Hallo
|
||||
noindent
|
||||
'''.toString,processor.process(node).toString)
|
||||
}
|
||||
|
||||
|
||||
@Test def void testTemplateProcessing() {
|
||||
val root = loc(0)
|
||||
|
|
|
@ -67,6 +67,21 @@ public class GeneratorNodeTest {
|
|||
Assert.assertEquals(_builder_1.toString(), result.getTraceRegion().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyIndent() {
|
||||
final LocationData root = this.loc(0);
|
||||
CompositeGeneratorNode node = this.exts.appendNewLine(this.exts.append(this.exts.trace(root), "Hallo"));
|
||||
this.exts.indent(node);
|
||||
this.exts.appendNewLine(this.exts.append(node, "noindent"));
|
||||
final GeneratorNodeProcessor processor = new GeneratorNodeProcessor();
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Hallo");
|
||||
_builder.newLine();
|
||||
_builder.append("noindent");
|
||||
_builder.newLine();
|
||||
Assert.assertEquals(_builder.toString(), processor.process(node).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateProcessing() {
|
||||
final LocationData root = this.loc(0);
|
||||
|
|
|
@ -51,11 +51,9 @@ class GeneratorNodeExtensions {
|
|||
* @return an indentation node, using the given indentString, appended as a child on the given parent
|
||||
*/
|
||||
def CompositeGeneratorNode indent(CompositeGeneratorNode parent, String indentString) {
|
||||
val text = new TextNode(indentString)
|
||||
parent.children += text
|
||||
val result = new IndentNode(indentString)
|
||||
parent.children += result
|
||||
return result
|
||||
val indent = new IndentNode(indentString)
|
||||
parent.children += indent
|
||||
return indent
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,6 +77,12 @@ class GeneratorNodeProcessor {
|
|||
* Indent nodes apply indentation between newline and content of its children.
|
||||
*/
|
||||
protected def dispatch void doProcess(IndentNode node, Context ctx) {
|
||||
// do nothing if the indent node is empty
|
||||
if (node.children.empty) {
|
||||
return;
|
||||
}
|
||||
ctx.pendingIndent = false;
|
||||
ctx.currentLine.append(node.indentationString)
|
||||
try {
|
||||
ctx.currentIndents.push(node.indentationString);
|
||||
doProcessChildren(node, ctx);
|
||||
|
|
|
@ -62,13 +62,10 @@ public class GeneratorNodeExtensions {
|
|||
* @return an indentation node, using the given indentString, appended as a child on the given parent
|
||||
*/
|
||||
public CompositeGeneratorNode indent(final CompositeGeneratorNode parent, final String indentString) {
|
||||
final TextNode text = new TextNode(indentString);
|
||||
final IndentNode indent = new IndentNode(indentString);
|
||||
List<IGeneratorNode> _children = parent.getChildren();
|
||||
_children.add(text);
|
||||
final IndentNode result = new IndentNode(indentString);
|
||||
List<IGeneratorNode> _children_1 = parent.getChildren();
|
||||
_children_1.add(result);
|
||||
return result;
|
||||
_children.add(indent);
|
||||
return indent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -288,6 +288,12 @@ public class GeneratorNodeProcessor {
|
|||
* Indent nodes apply indentation between newline and content of its children.
|
||||
*/
|
||||
protected void _doProcess(final IndentNode node, final GeneratorNodeProcessor.Context ctx) {
|
||||
boolean _isEmpty = node.getChildren().isEmpty();
|
||||
if (_isEmpty) {
|
||||
return;
|
||||
}
|
||||
ctx.pendingIndent = false;
|
||||
ctx.currentLine().append(node.getIndentationString());
|
||||
try {
|
||||
ctx.currentIndents.push(node.getIndentationString());
|
||||
this.doProcessChildren(node, ctx);
|
||||
|
|
Loading…
Reference in a new issue