From 17fddc1cf4e3560389b9a79af8ae4dc16e03b888 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 24 Mar 2023 23:24:18 +0100 Subject: [PATCH] Printer: Fix HashMap printing spacing --- src/printer.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/printer.cpp b/src/printer.cpp index 753d6c3..efd672c 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -4,10 +4,12 @@ * SPDX-License-Identifier: MIT */ -#include "lexer.h" +#include // std::next + #include "ruc/format/print.h" #include "error.h" +#include "lexer.h" #include "printer.h" #include "types.h" @@ -53,9 +55,9 @@ void Printer::dumpImpl(ASTNode* node) print("("); m_firstNode = false; m_previousNodeIsList = true; - List* list = static_cast(node); - for (size_t i = 0; i < list->nodes().size(); ++i) { - dumpImpl(list->nodes()[i]); + auto nodes = static_cast(node)->nodes(); + for (size_t i = 0; i < nodes.size(); ++i) { + dumpImpl(nodes[i]); m_previousNodeIsList = false; } print(")"); @@ -65,9 +67,9 @@ void Printer::dumpImpl(ASTNode* node) print("["); m_firstNode = false; m_previousNodeIsList = true; - Vector* vector = static_cast(node); - for (size_t i = 0; i < vector->nodes().size(); ++i) { - dumpImpl(vector->nodes()[i]); + auto nodes = static_cast(node)->nodes(); + for (size_t i = 0; i < nodes.size(); ++i) { + dumpImpl(nodes[i]); m_previousNodeIsList = false; } print("]"); @@ -77,12 +79,16 @@ void Printer::dumpImpl(ASTNode* node) print("{{"); m_firstNode = false; m_previousNodeIsList = true; - HashMap* hash_map = static_cast(node); - for (auto element : hash_map->elements()) { - print("{} ", element.first.front() == 0x7f ? ":" + element.first.substr(1) : element.first); // 127 - dumpImpl(element.second); - m_previousNodeIsList = false; + auto elements = static_cast(node)->elements(); + for (auto it = elements.begin(); it != elements.end(); ++it) { + print("{} ", it->first.front() == 0x7f ? ":" + it->first.substr(1) : it->first); // 127 + dumpImpl(it->second); + + if (it != elements.end() && std::next(it) != elements.end()) { + print(" "); + } } + m_previousNodeIsList = false; print("}}"); } else if (is(node)) {