Commit 04a0f53e authored by 0xJMR's avatar 0xJMR
Browse files

Added conditions.

parent bf119697
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.ast.ASTNode;
import de.monticore.commonexpressions._ast.*;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.math._ast.*;
import de.monticore.lang.matrix._ast.ASTMathMatrixAccessExpression;
import de.monticore.lang.matrix._ast.ASTMathMatrixValueExplicitExpression;
......@@ -21,10 +22,12 @@ import de.monticore.types.types._ast.ASTQualifiedName;
public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUnit>, MathStructuredVisitor {
protected final IndentPrinter printer;
protected boolean importVisited;
protected boolean inMatrixEnvironment;
public MathPrettyPrinter() {
this.printer = new IndentPrinter();
this.importVisited = false;
this.inMatrixEnvironment = false;
}
@Override
......@@ -363,6 +366,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void visit(ASTMathMatrixValueExplicitExpression node) {
this.inMatrixEnvironment = true;
this.printLeftSquareBracket();
}
......@@ -375,6 +379,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void endVisit(ASTMathMatrixValueExplicitExpression node) {
this.printRightSquareBracket();
this.inMatrixEnvironment = false;
}
@Override
......@@ -436,12 +441,12 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public void visit(ASTMathMatrixAccessExpression node) {
this.printLeftBracket();
if (!this.inMatrixEnvironment) this.printLeftBracket();
}
@Override
public void endVisit(ASTMathMatrixAccessExpression node) {
this.printRightBracket();
if (!this.inMatrixEnvironment) this.printRightBracket();
}
@Override
......
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;
......@@ -76,4 +77,19 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
this.printSpace();
this.printImageTag(node);
}
@Override
public void visit(ASTMathIfExpression node) {
this.printer.println();
this.printIf();
this.printSpace();
this.printImageTag(node);
}
@Override
public void visit(ASTMathElseIfExpression node) {
this.printElseIf();
this.printSpace();
this.printImageTag(node);
}
}
package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.lang.math._ast.ASTMathAssignmentDeclarationStatement;
import de.monticore.lang.math._ast.ASTMathAssignmentStatement;
import de.monticore.lang.math._ast.ASTMathDeclarationStatement;
import de.monticore.lang.math._ast.ASTMathForLoopHead;
import de.monticore.lang.math._ast.*;
public interface TeXHTMLMathStructuredVisitor extends MathStructuredVisitor {
@Override
......@@ -20,4 +17,18 @@ public interface TeXHTMLMathStructuredVisitor extends MathStructuredVisitor {
@Override
default void traverse(ASTMathForLoopHead node) {}
@Override
default void traverse(ASTMathIfExpression node) {
if (null != node.getBody()) {
node.getBody().accept(this.getRealThis());
}
}
@Override
default void traverse(ASTMathElseIfExpression node) {
if (null != node.getBody()) {
node.getBody().accept(this.getRealThis());
}
}
}
package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.commonexpressions._ast.ASTDivideExpression;
import de.monticore.commonexpressions._ast.ASTModuloExpression;
import de.monticore.commonexpressions._ast.ASTMultExpression;
import de.monticore.commonexpressions._ast.*;
import de.monticore.lang.math._ast.*;
import de.monticore.lang.matrix._ast.ASTMathMatrixAccessExpression;
import de.monticore.lang.matrix._ast.ASTMathMatrixValueExplicitExpression;
......@@ -11,12 +9,6 @@ import de.monticore.lang.matrixexpressions._ast.ASTMathArithmeticMatrixSolutionE
import de.monticore.numberunit._ast.ASTTimeDiv;
public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathStructuredVisitor {
protected boolean inMatrixEnvironment;
public TeXMathPrettyPrinter() {
this.inMatrixEnvironment = false;
}
@Override
public void visit(ASTElementType node) {
String printedNode = String.format("\\mathbb{%s}", node.getName());
......@@ -121,17 +113,22 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
public void revisit(ASTMathArithmeticMatrixEEPowExpression node) {
this.printer.print(".\\hat{}~");
this.printer.print("^{\\circ~");
}
@Override
public void endVisit(ASTMathArithmeticMatrixEEPowExpression node) {
this.printer.print("}");
}
@Override
public void revisit(ASTModuloExpression node) {
this.printer.print("~\\%~");
this.printer.print("~\\text{mod}~");
}
@Override
public void revisit(ASTMathArithmeticMatrixSolutionExpression node) {
this.printer.print("~.\\backslash\\backslash~");
this.printer.print("~\\backslash\\backslash~");
}
@Override
......@@ -141,4 +138,62 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
this.printer.print("=");
this.printSpace();
}
@Override
public void visit(ASTBracketExpression node) {
this.printer.print("\\left(");
}
@Override
public void endVisit(ASTBracketExpression node) {
this.printer.print("\\right)");
}
@Override
public void visit(ASTLessThanExpression node) {
this.printSpace();
this.printer.print("<");
this.printSpace();
}
@Override
public void visit(ASTLessEqualExpression node) {
this.printSpace();
this.printer.print("\\leqslant");
this.printSpace();
}
@Override
public void revisit(ASTGreaterThanExpression node) {
this.printSpace();
this.printer.print(">");
this.printSpace();
}
@Override
public void revisit(ASTGreaterEqualExpression node) {
this.printSpace();
this.printer.print("\\geqslant");
this.printSpace();
}
@Override
public void revisit(ASTBooleanOrOpExpression node) {
this.printSpace();
this.printer.print("\\lor");
this.printSpace();
}
@Override
public void revisit(ASTBooleanAndOpExpression node) {
this.printSpace();
this.printer.print("\\land");
this.printSpace();
}
@Override
public void visit(ASTMathIfExpression node) {}
@Override
public void visit(ASTMathElseIfExpression node) {}
}
package de.monticore.lang.monticar.mpp.montimath;
import de.monticore.lang.math._ast.ASTMathElseIfExpression;
import de.monticore.lang.math._ast.ASTMathIfExpression;
public interface TeXMathStructuredVisitor extends MathStructuredVisitor {
@Override
default void traverse(ASTMathIfExpression node) {
if (null != node.getCondition()) {
node.getCondition().accept(this.getRealThis());
}
}
@Override
default void traverse(ASTMathElseIfExpression node) {
if (null != node.getCondition()) {
node.getCondition().accept(this.getRealThis());
}
}
}
Supports Markdown
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