implement pretty print visitor

This commit is contained in:
2020-02-04 19:21:06 +01:00
parent 279ea28a29
commit 33904a3c33

View File

@@ -61,6 +61,13 @@ public class PrettyPrintVisitor implements Visitor<Void> {
ex.nl();
ex.nl();
}
for (var structDef: e.structs) {
structDef.welcome(this);
ex.nl();
ex.nl();
}
e.expression.welcome(this);
ex.write(";");
return null;
@@ -378,4 +385,24 @@ public class PrettyPrintVisitor implements Visitor<Void> {
return null;
}
@Override
public Void visit(StructDefinition e) {
ex.write("struct " + e.name + " {");
ex.addIndent();
for(var field: e.fields) {
ex.nl();
field.welcome(this);
}
ex.subIndent();
ex.nl();
ex.write("}");
return null;
}
@Override
public Void visit(StructField e) {
ex.write(e.name +": " + e.type.getName() + ";");
return null;
}
}