From 4cc2acc8a056cb9aa6b7e94dd64934dc2c6a880c Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 19 Nov 2023 14:19:30 +0100 Subject: [PATCH] Printer: Rename node -> value --- src/printer.cpp | 72 ++++++++++++++++++++++++------------------------- src/printer.h | 6 ++--- src/repl.cpp | 4 +-- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/printer.cpp b/src/printer.cpp index 48e7271..1b3c691 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -31,7 +31,7 @@ Printer::~Printer() // ----------------------------------------- -std::string Printer::print(ValuePtr node, bool print_readably) +std::string Printer::print(ValuePtr value, bool print_readably) { if (Error::the().hasAnyError()) { init(); @@ -39,18 +39,18 @@ std::string Printer::print(ValuePtr node, bool print_readably) return m_print; } - return printNoErrorCheck(node, print_readably); + return printNoErrorCheck(value, print_readably); } -std::string Printer::printNoErrorCheck(ValuePtr node, bool print_readably) +std::string Printer::printNoErrorCheck(ValuePtr value, bool print_readably) { init(); - if (node == nullptr) { + if (value == nullptr) { return {}; } - printImpl(node, print_readably); + printImpl(value, print_readably); return m_print; } @@ -64,7 +64,7 @@ void Printer::init() m_print = ""; } -void Printer::printImpl(ValuePtr node, bool print_readably) +void Printer::printImpl(ValuePtr value, bool print_readably) { bool pretty_print = Settings::the().get("pretty-print") == "1"; @@ -74,25 +74,25 @@ void Printer::printImpl(ValuePtr node, bool print_readably) } }; - Value* node_raw_ptr = node.get(); - if (is(node_raw_ptr)) { + Value* value_raw_ptr = value.get(); + if (is(value_raw_ptr)) { printSpacing(); - m_print += (is(node_raw_ptr)) ? '(' : '['; + m_print += (is(value_raw_ptr)) ? '(' : '['; m_first_node = false; m_previous_node_is_list = true; - auto nodes = std::static_pointer_cast(node)->nodesRead(); + auto nodes = std::static_pointer_cast(value)->nodesRead(); for (auto node : nodes) { printImpl(node, print_readably); m_previous_node_is_list = false; } - m_print += (is(node_raw_ptr)) ? ')' : ']'; + m_print += (is(value_raw_ptr)) ? ')' : ']'; } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); m_print += "{"; m_first_node = false; m_previous_node_is_list = true; - auto elements = std::static_pointer_cast(node)->elements(); + auto elements = std::static_pointer_cast(value)->elements(); for (auto it = elements.begin(); it != elements.end(); ++it) { m_print += ::format("{} ", (it->first.front() == 0x7f) ? ":" + it->first.substr(1) : '"' + it->first + '"'); // 127 printImpl(it->second, print_readably); @@ -104,8 +104,8 @@ void Printer::printImpl(ValuePtr node, bool print_readably) m_previous_node_is_list = false; m_print += '}'; } - else if (is(node_raw_ptr)) { - std::string text = std::static_pointer_cast(node)->data(); + else if (is(value_raw_ptr)) { + std::string text = std::static_pointer_cast(value)->data(); if (print_readably) { text = replaceAll(text, "\\", "\\\\"); text = replaceAll(text, "\"", "\\\""); @@ -120,44 +120,44 @@ void Printer::printImpl(ValuePtr node, bool print_readably) m_print += ::format("{}", text); } } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); - m_print += ::format(":{}", std::static_pointer_cast(node)->keyword().substr(1)); + m_print += ::format(":{}", std::static_pointer_cast(value)->keyword().substr(1)); } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); - m_print += ::format("{}", std::static_pointer_cast(node)->number()); + m_print += ::format("{}", std::static_pointer_cast(value)->number()); } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); - std::string value; - switch (std::static_pointer_cast(node)->state()) { - case Constant::Nil: value = "nil"; break; - case Constant::True: value = "true"; break; - case Constant::False: value = "false"; break; + std::string constant; + switch (std::static_pointer_cast(value)->state()) { + case Constant::Nil: constant = "nil"; break; + case Constant::True: constant = "true"; break; + case Constant::False: constant = "false"; break; } - m_print += ::format("{}", value); + m_print += ::format("{}", constant); } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); - m_print += ::format("{}", std::static_pointer_cast(node)->symbol()); + m_print += ::format("{}", std::static_pointer_cast(value)->symbol()); } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); - m_print += ::format("#({})", std::static_pointer_cast(node)->name()); + m_print += ::format("#({})", std::static_pointer_cast(value)->name()); } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); - m_print += ::format("#({:p})", node_raw_ptr); + m_print += ::format("#({:p})", value_raw_ptr); } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); - m_print += ::format("#({:p})", node_raw_ptr); + m_print += ::format("#({:p})", value_raw_ptr); } - else if (is(node_raw_ptr)) { + else if (is(value_raw_ptr)) { printSpacing(); m_print += "(atom "; - printImpl(std::static_pointer_cast(node)->deref(), print_readably); + printImpl(std::static_pointer_cast(value)->deref(), print_readably); m_print += ")"; } } diff --git a/src/printer.h b/src/printer.h index 88befcf..f99686a 100644 --- a/src/printer.h +++ b/src/printer.h @@ -17,12 +17,12 @@ public: Printer(); virtual ~Printer(); - std::string print(ValuePtr node, bool print_readably = true); - std::string printNoErrorCheck(ValuePtr node, bool print_readably = true); + std::string print(ValuePtr value, bool print_readably = true); + std::string printNoErrorCheck(ValuePtr value, bool print_readably = true); private: void init(); - void printImpl(ValuePtr node, bool print_readably = true); + void printImpl(ValuePtr value, bool print_readably = true); void printError(); bool m_first_node { true }; diff --git a/src/repl.cpp b/src/repl.cpp index 4d5a483..b02a3b7 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -74,11 +74,11 @@ auto eval(ValuePtr ast, EnvironmentPtr env) -> ValuePtr return eval.ast(); } -static auto print(ValuePtr exp) -> std::string +static auto print(ValuePtr value) -> std::string { Printer printer; - return printer.print(exp, true); + return printer.print(value, true); } static auto rep(std::string_view input, EnvironmentPtr env) -> std::string