#include "basic_printers.hpp" #include "error_handling.hpp" namespace printers { namespace utils { std::string to_printable_symbol(char ch) { switch (ch) { case '\a': return "\\a"; case '\b': return "\\b"; case '\e': return "\\e"; case '\f': return "\\f"; case '\n': return "\\n"; case '\r': return "\\r"; case '\t': return "\\t"; case '\v': return "\\v"; // case ' ': // return "\\s"; default: return std::string(1, ch); } } } // namespace utils void print_literal(const nodes::Literal &literal, Printer &printer) { switch (literal.get_any()->index()) { case 0: // double // print in parseable form ?? printer.print(literal.get().value()); return; case 1: // long long printer.print(literal.get().value()); return; case 2: // std::string printer.print("\"\""); // more efficient approach ?? for (auto &ch : *literal.get().value()) { printer.print(utils::to_printable_symbol(ch)); } printer.print("\"\""); return; case 3: // char printer.print("\'\'"); printer.print(utils::to_printable_symbol(*literal.get().value())); printer.print("\'\'"); return; case 4: // bool printer.print(literal.get().value() ? "true" : "false"); return; case 5: // unit printer.print("()"); return; case 6: // null printer.print("null"); return; default: break; } error_handling::handle_general_error("Unreachable"); exit(1); // unreachable } void print_identifier(const nodes::Identifier &identifier, Printer &printer) { printer.print(identifier.get()); } void print_annotation(const std::string &annotation, Printer &printer) { printer.print('@'); printer.print(annotation); } } // namespace printers