Browse Source

Meta: Improve formatting

master
Riyyi 2 years ago
parent
commit
f4e388716d
  1. 2
      src/ast.h
  2. 15
      src/printer.cpp
  3. 4
      src/reader.cpp

2
src/ast.h

@ -21,7 +21,7 @@
namespace blaze { namespace blaze {
class ASTNode; class ASTNode;
typedef std::shared_ptr<ASTNode> ASTNodePtr; typedef std::shared_ptr<ASTNode> ASTNodePtr;
class ASTNode { class ASTNode {
public: public:

15
src/printer.cpp

@ -5,6 +5,7 @@
*/ */
#include <iterator> // std::next #include <iterator> // std::next
#include <memory> // std::static_pointer_cast
#include <string> #include <string>
#include "ruc/format/format.h" #include "ruc/format/format.h"
@ -74,7 +75,7 @@ void Printer::printImpl(ASTNodePtr node)
m_print += '('; m_print += '(';
m_first_node = false; m_first_node = false;
m_previous_node_is_list = true; m_previous_node_is_list = true;
auto nodes = static_pointer_cast<List>(node)->nodes(); auto nodes = std::static_pointer_cast<List>(node)->nodes();
for (size_t i = 0; i < nodes.size(); ++i) { for (size_t i = 0; i < nodes.size(); ++i) {
printImpl(nodes[i]); printImpl(nodes[i]);
m_previous_node_is_list = false; m_previous_node_is_list = false;
@ -86,7 +87,7 @@ void Printer::printImpl(ASTNodePtr node)
m_print += '['; m_print += '[';
m_first_node = false; m_first_node = false;
m_previous_node_is_list = true; m_previous_node_is_list = true;
auto nodes = static_pointer_cast<Vector>(node)->nodes(); auto nodes = std::static_pointer_cast<Vector>(node)->nodes();
for (size_t i = 0; i < nodes.size(); ++i) { for (size_t i = 0; i < nodes.size(); ++i) {
printImpl(nodes[i]); printImpl(nodes[i]);
m_previous_node_is_list = false; m_previous_node_is_list = false;
@ -98,7 +99,7 @@ void Printer::printImpl(ASTNodePtr node)
m_print += "{"; m_print += "{";
m_first_node = false; m_first_node = false;
m_previous_node_is_list = true; m_previous_node_is_list = true;
auto elements = static_pointer_cast<HashMap>(node)->elements(); auto elements = std::static_pointer_cast<HashMap>(node)->elements();
for (auto it = elements.begin(); it != elements.end(); ++it) { for (auto it = elements.begin(); it != elements.end(); ++it) {
m_print += format("{} ", it->first.front() == 0x7f ? ":" + it->first.substr(1) : it->first); // 127 m_print += format("{} ", it->first.front() == 0x7f ? ":" + it->first.substr(1) : it->first); // 127
printImpl(it->second); printImpl(it->second);
@ -113,19 +114,19 @@ void Printer::printImpl(ASTNodePtr node)
else if (is<String>(node_raw_ptr)) { else if (is<String>(node_raw_ptr)) {
// TODO: Implement string readably printing // TODO: Implement string readably printing
printSpacing(); printSpacing();
m_print += format("{}", static_pointer_cast<String>(node)->data()); m_print += format("{}", std::static_pointer_cast<String>(node)->data());
} }
else if (is<Keyword>(node_raw_ptr)) { else if (is<Keyword>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format(":{}", static_pointer_cast<Keyword>(node)->keyword().substr(1)); m_print += format(":{}", std::static_pointer_cast<Keyword>(node)->keyword().substr(1));
} }
else if (is<Number>(node_raw_ptr)) { else if (is<Number>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format("{}", static_pointer_cast<Number>(node)->number()); m_print += format("{}", std::static_pointer_cast<Number>(node)->number());
} }
else if (is<Symbol>(node_raw_ptr)) { else if (is<Symbol>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format("{}", static_pointer_cast<Symbol>(node)->symbol()); m_print += format("{}", std::static_pointer_cast<Symbol>(node)->symbol());
} }
} }

4
src/reader.cpp

@ -7,7 +7,7 @@
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint64_t #include <cstdint> // uint64_t
#include <cstdlib> // std::strtoll #include <cstdlib> // std::strtoll
#include <memory> // makePtr, std::shared_ptr #include <memory> // std::static_pointer_cast
#include <utility> // std::move #include <utility> // std::move
#include "error.h" #include "error.h"
@ -196,7 +196,7 @@ ASTNodePtr Reader::readHashMap()
return nullptr; return nullptr;
} }
std::string keyString = is<String>(key.get()) ? static_pointer_cast<String>(key)->data() : static_pointer_cast<Keyword>(key)->keyword(); std::string keyString = is<String>(key.get()) ? std::static_pointer_cast<String>(key)->data() : std::static_pointer_cast<Keyword>(key)->keyword();
hash_map->addElement(keyString, value); hash_map->addElement(keyString, value);
} }

Loading…
Cancel
Save