basic printers, type printers, some fixes, part of expression printers

This commit is contained in:
ProgramSnail 2023-07-24 18:47:57 +03:00
parent 3914ff7d8b
commit 3669084f55
14 changed files with 795 additions and 39 deletions

View file

@ -0,0 +1,52 @@
#pragma once
#include "basic_nodes.hpp"
#include <iostream>
namespace printers {
class Printer {
public:
Printer(std::ostream &output, size_t tab_width,
bool print_words_instead_of_symbols)
: output_(output), tab_width_(tab_width),
print_words_instead_of_symbols_(print_words_instead_of_symbols),
current_column_(0) {}
template <typename T> void print(const T &value) { output_ << value; }
void new_line() {
print('\n');
print_spaces(current_column_ * tab_width_);
}
void indent() { ++current_column_; }
void deindent() { --current_column_; }
void tab() { print_spaces(tab_width_); }
void space() { print_spaces(1); }
bool print_words_instead_of_symbols() {
return print_words_instead_of_symbols_;
}
private:
void print_spaces(size_t n) { print(std::string(n, ' ')); }
private:
std::ostream &output_;
size_t tab_width_ = 2;
bool print_words_instead_of_symbols_ = false;
size_t current_column_ = 0;
};
void print_literal(const nodes::Literal &literal, Printer &printer);
void print_identifier(const nodes::Identifier &identifier, Printer &printer);
void print_annotation(const std::string &annotation, Printer &printer);
} // namespace printers