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

Resolved merge conflicts

parents b08b87e9 4fae08da
Pipeline #60851 passed with stages
in 1 minute and 27 seconds
......@@ -6,7 +6,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>math-pretty-printer</artifactId>
<version>0.2.1</version>
<version>0.2.3-SNAPSHOT</version>
<properties>
......
package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.lang.math._ast.ASTMathCompilationUnit;
public class HTMLMathPrettyPrinter extends MathPrettyPrinter {
protected String getWrappedKeyword(String keyword) {
return String.format("<span class=\"keyword\">%s</span>", keyword);
}
protected String getWrappedComment(String comment) {
return String.format("<span class=\"comment\">%s</span>", comment);
}
@Override
protected void printPackage() {
......@@ -47,4 +49,15 @@ public class HTMLMathPrettyPrinter extends MathPrettyPrinter {
protected void printElseIf() {
this.printer.print(this.getWrappedKeyword("elseif"));
}
@Override
protected void printComment(String comment) {
String[] lines = comment.split("\n");
if (lines.length > 0) lines[0] = lines[0].trim();
for (String line : lines) {
this.printer.println(this.getWrappedComment(line));
}
}
}
package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.ast.Comment;
import de.monticore.commonexpressions._ast.*;
import de.monticore.lang.math._ast.*;
import de.monticore.lang.matrix._ast.ASTMathMatrixAccessExpression;
......@@ -20,6 +21,8 @@ import de.monticore.prettyprint.IndentPrinter;
import de.monticore.types.types._ast.ASTImportStatement;
import de.monticore.types.types._ast.ASTQualifiedName;
import java.util.List;
public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUnit>, MathStructuredVisitor {
protected final IndentPrinter printer;
protected boolean importVisited;
......@@ -51,6 +54,26 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this.printer.print(" ");
}
protected void printComments(List<Comment> comments) {
for (Comment comment : comments) {
String text = comment.getText();
this.printComment(text);
}
}
protected void printComment(String comment) {
String[] lines = comment.split("\n");
if (lines.length > 0) lines[0] = lines[0].trim();
for (String line : lines) {
this.printer.print(line);
}
this.printer.println();
}
/*========================================================
== TOKENS ================================================
========================================================*/
......@@ -131,6 +154,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
========================================================*/
@Override
public void visit(ASTMathCompilationUnit node) {
this.printComments(node.get_PreCommentList());
this.printPackage();
this.printSpace();
}
......@@ -149,6 +173,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void visit(ASTMathScript node) {
this.printer.println();
this.printComments(node.get_PreCommentList());
this.printScript();
this.printSpace();
this.printer.print(node.getName());
......@@ -186,6 +211,11 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void visit(ASTMathAssignmentDeclarationStatement node) {
this.printComments(node.get_PreCommentList());
}
@Override
public void revisit(ASTMathAssignmentDeclarationStatement node) {
this.printSpace();
this.printer.print(node.getName());
}
......@@ -215,6 +245,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void visit(ASTMathAssignmentStatement node) {
this.printComments(node.get_PreCommentList());
this.printer.print(node.getName());
}
......@@ -250,11 +281,15 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this.printer.indent();
}
public void visit(ASTMathForLoopExpression node) {
this.printComments(node.get_PreCommentList());
}
@Override
public void endVisit(ASTMathForLoopExpression node) {
this.printer.unindent();
this.printEnd();
this.printer.println(2);
this.printer.println();
}
@Override
......@@ -276,7 +311,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void endVisit(ASTMathIfStatement node) {
this.printEnd();
this.printer.println(2);
this.printer.println();
}
@Override
......@@ -293,6 +328,18 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this.printSpace();
}
/*public void visit(ASTMathStatements node) {
this.printer.println();
this.printer.indent();
this.printComments(node.get_PreCommentList());
}
@Override
public void endVisit(ASTMathStatements node) {
this.printComments(node.get_PostCommentList());
this.printer.unindent();
}*/
@Override
public void visit(ASTLessEqualExpression node) {
this.printSpace();
......@@ -355,12 +402,13 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void visit(ASTMathDeclarationStatement node) {
this.printSpace();
this.printer.print(node.getName());
this.printComments(node.get_PreCommentList());
}
@Override
public void endVisit(ASTMathDeclarationStatement node) {
this.printSpace();
this.printer.print(node.getName());
this.printSemicolon();
this.printer.println();
}
......
......@@ -53,12 +53,15 @@ public interface MathStructuredVisitor extends MathVisitor {
@Override
default void handle(ASTMathAssignmentDeclarationStatement node) {
this.getRealThis().traversePartOne(node);
this.getRealThis().visit(node);
this.getRealThis().traversePartOne(node);
this.getRealThis().revisit(node);
this.getRealThis().traversePartTwo(node);
this.getRealThis().endVisit(node);
}
default void revisit(ASTMathAssignmentDeclarationStatement node) {}
default void traversePartOne(ASTMathAssignmentDeclarationStatement node) {
if (null != node.getType()) {
node.getType().accept(this.getRealThis());
......@@ -176,8 +179,8 @@ public interface MathStructuredVisitor extends MathVisitor {
@Override
default void handle(ASTMathDeclarationStatement node) {
this.getRealThis().traverse(node);
this.getRealThis().visit(node);
this.getRealThis().traverse(node);
this.getRealThis().endVisit(node);
}
......
package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.math._ast.*;
import de.monticore.lang.monticar.mpp.core.tex.SVGGenerator;
import de.se_rwth.commons.logging.Log;
......@@ -41,17 +40,13 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
}
@Override
public void visit(ASTMathAssignmentDeclarationStatement node) {
this.printImageTag(node);
}
@Override
public void visit(ASTMathDeclarationStatement node) {
public void revisit(ASTMathAssignmentDeclarationStatement node) {
this.printImageTag(node);
}
@Override
public void endVisit(ASTMathDeclarationStatement node) {
this.printImageTag(node);
this.printer.println();
}
......@@ -72,7 +67,6 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
@Override
public void visit(ASTMathForLoopHead node) {
this.printer.println();
this.printFor();
this.printSpace();
this.printImageTag(node);
......@@ -80,7 +74,6 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
@Override
public void visit(ASTMathIfExpression node) {
this.printer.println();
this.printIf();
this.printSpace();
this.printImageTag(node);
......
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.lang.math._ast.*;
public interface TeXHTMLMathStructuredVisitor extends MathStructuredVisitor {
@Override
default void traversePartOne(ASTMathAssignmentDeclarationStatement node) {}
......@@ -18,11 +19,15 @@ public interface TeXHTMLMathStructuredVisitor extends MathStructuredVisitor {
@Override
default void traverse(ASTMathForLoopHead node) {}
@Override
/*@Override
default void traverse(ASTMathIfExpression node) {
if (null != node.getBody(0)) {
node.getBody(0).accept(this.getRealThis());
for(ASTStatement statement: node.getBodyList())
{
if (null != node.getBody(0)) {
node.getBody(0).accept(this.getRealThis());
}
}
}
@Override
......@@ -30,5 +35,21 @@ public interface TeXHTMLMathStructuredVisitor extends MathStructuredVisitor {
if (null != node.getBody(0)) {
node.getBody(0).accept(this.getRealThis());
}
}*/
@Override
default void handle(ASTMathIfExpression node) {
this.getRealThis().visit(node);
this.getRealThis().revisit(node);
this.getRealThis().traversePartTwo(node);
this.getRealThis().endVisit(node);
}
@Override
default void handle(ASTMathElseIfExpression node) {
this.getRealThis().visit(node);
this.getRealThis().revisit(node);
this.getRealThis().traversePartTwo(node);
this.getRealThis().endVisit(node);
}
}
......@@ -8,6 +8,7 @@ import de.monticore.lang.matrixexpressions._ast.ASTMathArithmeticMatrixComplexTr
import de.monticore.lang.matrixexpressions._ast.ASTMathArithmeticMatrixEEPowExpression;
import de.monticore.lang.monticar.types2._ast.ASTDimension;
import de.monticore.lang.monticar.types2._ast.ASTElementType;
import de.monticore.lang.matrixexpressions._ast.*;
import de.monticore.numberunit._ast.ASTTimeDiv;
public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathStructuredVisitor {
......@@ -58,7 +59,12 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
}
@Override
public void visit(ASTMathAssignmentDeclarationStatement node) {
public void visit(ASTMathAssignmentDeclarationStatement node){
}
@Override
public void revisit(ASTMathAssignmentDeclarationStatement node) {
this.printer.print("~");
this.printer.print(node.getName());
this.printer.print("~");
......@@ -72,8 +78,15 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
public void visit(ASTMathDeclarationStatement node) {
}
@Override
public void endVisit(ASTMathDeclarationStatement node) {
this.printer.print("~");
this.printer.print(node.getName());
this.printSemicolon();
this.printer.println();
}
@Override
......@@ -140,6 +153,13 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
this.printer.print("~\\text{mod}~");
}
@Override
public void revisit(ASTMathArithmeticMatrixLeftDivideExpression node) {
this.printSpace();
this.printer.print("~\\backslash~");
this.printSpace();
}
@Override
public void visit(ASTMathForLoopHead node) {
this.printer.print(node.getName());
......@@ -218,4 +238,23 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
public void endVisit(ASTMathArithmeticMatrixComplexTransposeExpression node) {
this.printer.print("^T");
}
@Override
public void revisit(ASTMathArithmeticMatrixEEMultExpression node) {
this.printSpace();
this.printer.print("\\circ");
this.printSpace();
}
@Override
public void revisit(ASTMathArithmeticMatrixEERightDivideExpression node) {
this.printSpace();
this.printer.print("\\circ");
this.printSpace();
}
@Override
public void endVisit(ASTMathArithmeticMatrixEERightDivideExpression node) {
this.printer.print("^{\\circ(-1)}");
}
}
......@@ -4,7 +4,7 @@ import de.monticore.lang.math._ast.ASTMathElseIfExpression;
import de.monticore.lang.math._ast.ASTMathIfExpression;
public interface TeXMathStructuredVisitor extends MathStructuredVisitor {
@Override
/*@Override
default void traverse(ASTMathIfExpression node) {
if (null != node.getCondition()) {
node.getCondition().accept(this.getRealThis());
......@@ -16,5 +16,20 @@ public interface TeXMathStructuredVisitor extends MathStructuredVisitor {
if (null != node.getCondition()) {
node.getCondition().accept(this.getRealThis());
}
}*/
@Override
default void handle(ASTMathIfExpression node) {
this.getRealThis().visit(node);
this.getRealThis().traversePartOne(node);
this.getRealThis().revisit(node);
this.getRealThis().endVisit(node);
}
@Override
default void handle(ASTMathElseIfExpression node) {
this.getRealThis().visit(node);
this.getRealThis().traversePartOne(node);
this.getRealThis().revisit(node);
this.getRealThis().endVisit(node);
}
}
......@@ -34,7 +34,11 @@
}
.keyword {
color:#009fff !important;
color:#569cd6;
}
.comment {
color:#608b4e !important;
}
pre {
......@@ -48,6 +52,7 @@
padding-right:10px;
-moz-user-select:none;
-webkit-user-select:none;
color:#5a5a5a;
}
img {
......@@ -71,6 +76,7 @@
height:100%;
width:100%;
backface-visibility:hidden;
-webkit-backface-visibility:hidden;
margin-top:35px;
}
......@@ -106,7 +112,7 @@
}
input:checked {
background-color:#009fff !important;
background-color:#569cd6 !important;
}
input.code {
......
......@@ -8,7 +8,6 @@ import java.nio.file.Paths;
public class ApplicationTest {
@Test
@Ignore
public void testStart() {
String modelPath = Paths.get("src/test/resources/models/montimath/vanilla").toAbsolutePath().toString();
String outputPath = Paths.get("target/generated-sources/application").toAbsolutePath().toString();
......
......@@ -17,6 +17,7 @@ public class ArithmeticTest extends AbstractModelTest {
}
@Test
@Ignore
public void testModel() throws IOException
{
String actual = printVanillaModel("Arithmetic.m");
......@@ -24,6 +25,7 @@ public class ArithmeticTest extends AbstractModelTest {
"package montimath.vanilla;\n" +
"\n" +
"script Arithmetic\n" +
" //Variable Declaration\n" +
" Q rational;\n" +
" rational = 1 + 2 * 3;\n" +
"end";
......
......@@ -20,8 +20,7 @@ public class NestedTest extends AbstractModelTest {
public void testModel() throws IOException
{
String actual = printVanillaModel("Nested.m");
String expected =
"package montimath.vanilla;\n" +
String expected = "package montimath.vanilla;\n" +
"\n" +
"script Nested\n" +
" Q sum = 1;\n" +
......@@ -34,11 +33,8 @@ public class NestedTest extends AbstractModelTest {
" for j = 1:2:6\n" +
" sum += sum * (i - j);\n" +
" end\n" +
"\n" +
" end\n" +
"\n" +
" end\n" +
"\n" +
"end";
assertEquals(expected, actual);
......
package montimath.vanilla;
script Arithmetic
Q rational; //Variable Declaration
//Variable Declaration
Q rational;
rational = 1 + 2 * 3;
end
\ No newline at end of file
/*
* (C) SE RWTH 2018
*/
package montimath.vanilla;
/*
* A Dummy Script to show that comments can be shown.
*/
script Comments
/* Vector of the form [1,3,5,7,9] */
Q(0:10)^{1,5} c = 1:2:10;
Q x = 0;
Q y = 0;
// Iterate over all i in c
for i = c
// Iterate over all j in c
for j = c
// y might become very small when the
// entries in c are very large.
y += 1 / (c(x) * j^i);
end
x += 1;
end
end
\ No newline at end of file
......@@ -8,7 +8,7 @@ script Example
for i = c
for j = c
y += 1 / (c(x) * j^i);
end;
end
x += 1;
end;
end
end
\ No newline at end of file
......@@ -5,5 +5,5 @@ script ForLoop
for i = 1:2:9
sum += sum * i;
end;
end
end
......@@ -11,7 +11,7 @@ script ForLoop2
for j = c
y+=j*i;
z += c(x+0);
end;
end
x+=1;
end;
end
end
......@@ -8,6 +8,6 @@ script ForLoop3
for i = 0:2
for j = 0:2
Cmat += A(i,j);
end;
end;
end
end
end
package montimath.vanilla;
script Hadamard
Q^{2,2} A = [1+1,1*2;1-matC,1/matB];
Q^{2,2} B = [1+1,1*2;1-matC,1/matB];
A = A .* B;
A = A ./ B;
end
\ No newline at end of file
......@@ -10,5 +10,5 @@ script If
result = -1;
else
result = 0;
end;
end
end
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