Browse Source

Printer: Fix HashMap printing spacing

master
Riyyi 2 years ago
parent
commit
17fddc1cf4
  1. 30
      src/printer.cpp

30
src/printer.cpp

@ -4,10 +4,12 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "lexer.h" #include <iterator> // std::next
#include "ruc/format/print.h" #include "ruc/format/print.h"
#include "error.h" #include "error.h"
#include "lexer.h"
#include "printer.h" #include "printer.h"
#include "types.h" #include "types.h"
@ -53,9 +55,9 @@ void Printer::dumpImpl(ASTNode* node)
print("("); print("(");
m_firstNode = false; m_firstNode = false;
m_previousNodeIsList = true; m_previousNodeIsList = true;
List* list = static_cast<List*>(node); auto nodes = static_cast<List*>(node)->nodes();
for (size_t i = 0; i < list->nodes().size(); ++i) { for (size_t i = 0; i < nodes.size(); ++i) {
dumpImpl(list->nodes()[i]); dumpImpl(nodes[i]);
m_previousNodeIsList = false; m_previousNodeIsList = false;
} }
print(")"); print(")");
@ -65,9 +67,9 @@ void Printer::dumpImpl(ASTNode* node)
print("["); print("[");
m_firstNode = false; m_firstNode = false;
m_previousNodeIsList = true; m_previousNodeIsList = true;
Vector* vector = static_cast<Vector*>(node); auto nodes = static_cast<Vector*>(node)->nodes();
for (size_t i = 0; i < vector->nodes().size(); ++i) { for (size_t i = 0; i < nodes.size(); ++i) {
dumpImpl(vector->nodes()[i]); dumpImpl(nodes[i]);
m_previousNodeIsList = false; m_previousNodeIsList = false;
} }
print("]"); print("]");
@ -77,12 +79,16 @@ void Printer::dumpImpl(ASTNode* node)
print("{{"); print("{{");
m_firstNode = false; m_firstNode = false;
m_previousNodeIsList = true; m_previousNodeIsList = true;
HashMap* hash_map = static_cast<HashMap*>(node); auto elements = static_cast<HashMap*>(node)->elements();
for (auto element : hash_map->elements()) { for (auto it = elements.begin(); it != elements.end(); ++it) {
print("{} ", element.first.front() == 0x7f ? ":" + element.first.substr(1) : element.first); // 127 print("{} ", it->first.front() == 0x7f ? ":" + it->first.substr(1) : it->first); // 127
dumpImpl(element.second); dumpImpl(it->second);
m_previousNodeIsList = false;
if (it != elements.end() && std::next(it) != elements.end()) {
print(" ");
}
} }
m_previousNodeIsList = false;
print("}}"); print("}}");
} }
else if (is<String>(node)) { else if (is<String>(node)) {

Loading…
Cancel
Save