gendisplayvis.beh.html
Program{
void addDisplayVisitor(String name)(@
addClassDef(ClassDef.parse("*notparsed* *visitor* " + name
+ " = <indent> int."));
@)
void generateDisplayVisitor(String name, File file)=allParts{
before Program (@
host.openOutputFile(file);
Program.out.println(host.genericOutputVisitorPreamble(name));
@)
(@ ClassName classname; @)
before ClassDef (@
classname = host.get_classname();
// don't do anything for alternation classes
if (host.isAlternationClass()) return;
boolean rep = classname.isOrWasRepetitionClass();
String body =
" out.print(\": " + classname + " "
+ (rep ? "{" : "(") + "\");\n"
+ " indent++;\n";
Program.out.println(classname.makeBefore(body));
body =
" out.print(\" "
+ (rep ? "}" : ")") + "\");\n"
+ " indent--;\n";
Program.out.println(classname.makeAfter(body));
@)
before Part (@
ClassName dest = host.get_classname();
String deststr = dest.toString();
PartName partname = host.get_partname();
String body =
" out.println();"
+ " for (int i = 0; i < indent; i++) out.print(\"\\t\");\n"
+ " out.print(\"<" + partname + "> \");\n";
if (dest.isBuiltinType()) {
if (deststr.equals("char")) {
body += " out.print(\" '\""
+ " + source.get_" + partname + "() + \"' \");\n";
} else {
body += " out.print(\" : "
+ dest + " \\\"\" + dest + \"\\\"\");\n";
}
} else if (dest.isTerminalClass()) {
body += " out.print(\" : " + dest + "\");\n";
if (deststr.equals("String")) {
body += " out.print(\" \\\"\""
+ " + source.get_" + partname + "() + \"\\\" \");\n";
} else if (deststr.equals("Text")) {
body += " out.print(\" " + Text.begin + "\""
+ " + source.get_" + partname + "() + "
+ Text.quoted_end + " + \" \");\n";
} else if (deststr.equals("Character")) {
body += " out.print(\" '\""
+ " + source.get_" + partname + "() + \"' \");\n";
} else {
body += " out.print(\" \\\"\" + source.get_" + partname + "() + \"\\\"\");\n";
}
}
Program.out.println(host.makeBefore(classname, body));
@)
after Program (@
Program.out.println("}");
host.closeOutputFile();
@)
}
}