X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fsolver%2Fformula%2FPrintVisitor.java;fp=bundles%2Forg.simantics.spreadsheet%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fsolver%2Fformula%2FPrintVisitor.java;h=1738feb77f8d645c673bfa8b66df26c7edca90ab;hb=c07a3818f0024e932a27eb85cbfd3f2291475a65;hp=0000000000000000000000000000000000000000;hpb=6c99e980d250fb9201aba93be7dcb1f55564dccd;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/PrintVisitor.java b/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/PrintVisitor.java new file mode 100644 index 000000000..1738feb77 --- /dev/null +++ b/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/PrintVisitor.java @@ -0,0 +1,168 @@ +package org.simantics.spreadsheet.solver.formula; + +import org.simantics.spreadsheet.solver.formula.parser.ast.AstApply; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstArgList; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstArithmeticExpression; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstArray; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstArrayFormulaReference; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstBoolean; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstDouble; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstFactor; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstIdentifier; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstInteger; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstNothing; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstNull; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstRange; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstRelation; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstString; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstTerm; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstValue; +import org.simantics.spreadsheet.solver.formula.parser.ast.AstValueVisitor; + +public class PrintVisitor implements AstValueVisitor { + + @Override + public String visit(AstBoolean astBoolean) { + return "" + astBoolean.value; + } + + @Override + public String visit(AstDouble astFloat) { + return "" + astFloat.value; + } + + @Override + public String visit(AstInteger astInteger) { + return "" + astInteger.value; + } + + @Override + public String visit(AstNull astNull) { + return "AstNull"; + } + + @Override + public String visit(AstString astString) { + return "\"" + astString.value + "\""; + } + + @Override + public String visit(AstRange astRange) { + if(astRange.isCell()) { + return astRange.first; + } else { + return astRange.first + ":" + astRange.second; + } + } + + @Override + public String visit(AstArgList astArgList) { + StringBuilder b = new StringBuilder(); + for(int i=0;i 0) b.append(";"); + b.append(astArgList.values.get(i).accept(this)); + } + return b.toString(); + } + + @Override + public String visit(AstApply astApply) { + if(astApply.args == null) { + return astApply.value + "()"; + } else { + return astApply.value + "(" + astApply.args.accept(this) + ")"; + } + } + + @Override + public String visit(AstRelation astRelation) { + + StringBuilder b = new StringBuilder(); + b.append(astRelation.left.accept(this)); + b.append(astRelation.op.trim()); + b.append(astRelation.right.accept(this)); + return b.toString(); + + } + + @Override + public String visit(AstArithmeticExpression exp) { + + StringBuilder b = new StringBuilder(); + if(exp.prefix != null) b.append(exp.prefix); + + b.append(exp.left.accept(this)); + + for(int i=0;i 0) b.append(";"); + b.append(array.values.get(i).accept(this)); + } + return b.toString(); + } + + @Override + public String visit(AstNothing array) { + return "AstNothing"; + } + + @Override + public String visit(AstArrayFormulaReference ref) { + return "{" + ref.value.accept(this) + "}"; + } + +}