Commit f8eb7ed1 authored by Bram Kohlen's avatar Bram Kohlen
Browse files

MathPrettyPrinter can print the individual statements of a script now

parent e690cd97
Pipeline #61170 passed with stages
in 1 minute and 33 seconds
......@@ -27,18 +27,36 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
protected final IndentPrinter printer;
protected boolean importVisited;
protected boolean inMatrixEnvironment;
protected boolean internal;
public MathPrettyPrinter() {
public MathPrettyPrinter(boolean internal, int spacing) {
this.printer = new IndentPrinter();
this.printer.setIndentLength(4);
this.printer.setIndentLength(spacing);
this.importVisited = false;
this.inMatrixEnvironment = false;
this.internal = internal;
}
public MathPrettyPrinter(boolean internal)
{
this(internal, 4);
}
public MathPrettyPrinter()
{
this(false,4);
}
@Override
public String prettyPrint(ASTMathCompilationUnit node) {
this.printer.clearBuffer();
this.handle(node);
if(internal) {
this.printStatements(node);
}
else {
this.handle(node);
}
return this.printer.getContent();
}
......@@ -50,6 +68,16 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
return this.printer.getContent();
}
protected void printStatements(ASTMathCompilationUnit node)
{
List<ASTStatement> statements = node.getMathScript().getStatementsList();
for(ASTStatement statement: statements)
{
statement.accept(this);
}
}
protected void printSpace() {
this.printer.print(" ");
}
......
package de.monticore.lang.monticar.mpp.models;
import de.monticore.lang.monticar.mpp.montimath.MathPrettyPrinter;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
import static junit.framework.TestCase.assertEquals;
public class StatementsOnlyTest extends AbstractModelTest {
@Test
@Ignore
public void printTest3() throws IOException
{
this.printer = new MathPrettyPrinter(true);
System.out.println(printVanillaModel("Nested.m"));
}
@Test
public void testModel3() throws IOException
{
this.printer = new MathPrettyPrinter(true);
String actual = printVanillaModel("Nested.m");
String expected =
"Q sum = 1;\n" +
"for i = 1:2:9\n" +
" if i < 2\n" +
" sum -= sum * i;\n" +
" elseif i < 4\n" +
" sum += sum * i;\n" +
" else\n" +
" for j = 1:2:6\n" +
" sum += sum * (i - j);\n" +
" end\n" +
" end\n" +
"end\n";
assertEquals(expected, actual);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment