com.laamella.sexpression.visitor.PrinterVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of s-expressions Show documentation
Show all versions of s-expressions Show documentation
S-Expression support for Java
package com.laamella.sexpression.visitor;
import com.laamella.sexpression.model.Atom;
import com.laamella.sexpression.model.AtomList;
import com.laamella.sexpression.model.Comment;
import com.laamella.sexpression.model.SExpression;
public class PrinterVisitor implements Visitor {
public static final PrinterVisitor TO_STRING = new PrinterVisitor();
@Override
public Void accept(Atom atom, Appendable output) throws Exception {
for (char c : atom.value.toCharArray()) {
if (Character.isWhitespace(c)) {
output.append('"').append(atom.value).append('"');
return null;
}
}
output.append(atom.value);
return null;
}
@Override
public Void accept(AtomList atomList, Appendable output) throws Exception {
output.append('(');
String space = "";
for (SExpression n : atomList.values) {
output.append(space);
n.visit(this, output);
space = " ";
}
output.append(')');
return null;
}
@Override
public Void accept(Comment comment, Appendable output) throws Exception {
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy