Everywhere: Rename addNode and addError functions -> add
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace blaze {
|
||||
|
||||
void Collection::addNode(ASTNodePtr node)
|
||||
void Collection::add(ASTNodePtr node)
|
||||
{
|
||||
m_nodes.push_back(node);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
virtual bool isCollection() const override { return true; }
|
||||
|
||||
void addNode(ASTNodePtr node);
|
||||
void add(ASTNodePtr node);
|
||||
|
||||
const std::list<ASTNodePtr>& nodes() const { return m_nodes; }
|
||||
size_t size() const { return m_nodes.size(); }
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ EnvironmentPtr Environment::create(const ASTNodePtr lambda, std::list<ASTNodePtr
|
||||
|
||||
auto list = makePtr<List>();
|
||||
for (; it != arguments.end(); ++it) {
|
||||
list->addNode(*it);
|
||||
list->add(*it);
|
||||
}
|
||||
env->set(bindings[i + 1], list);
|
||||
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ public:
|
||||
m_token_errors.clear();
|
||||
m_other_errors.clear();
|
||||
}
|
||||
void addError(Token error) { m_token_errors.push_back(error); }
|
||||
void addError(const std::string& error) { m_other_errors.push_back(error); }
|
||||
void add(Token error) { m_token_errors.push_back(error); }
|
||||
void add(const std::string& error) { m_other_errors.push_back(error); }
|
||||
|
||||
bool hasTokenError() { return m_token_errors.size() > 0; }
|
||||
bool hasOtherError() { return m_other_errors.size() > 0; }
|
||||
|
||||
+14
-14
@@ -82,7 +82,7 @@ ASTNodePtr Eval::evalAst(ASTNodePtr ast, EnvironmentPtr env)
|
||||
if (is<Symbol>(ast_raw_ptr)) {
|
||||
auto result = env->get(std::static_pointer_cast<Symbol>(ast)->symbol());
|
||||
if (!result) {
|
||||
Error::the().addError(format("'{}' not found", ast));
|
||||
Error::the().add(format("'{}' not found", ast));
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
@@ -95,7 +95,7 @@ ASTNodePtr Eval::evalAst(ASTNodePtr ast, EnvironmentPtr env)
|
||||
if (eval_node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
result->addNode(eval_node);
|
||||
result->add(eval_node);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ ASTNodePtr Eval::evalAst(ASTNodePtr ast, EnvironmentPtr env)
|
||||
if (eval_node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
result->addNode(eval_node);
|
||||
result->add(eval_node);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ ASTNodePtr Eval::evalAst(ASTNodePtr ast, EnvironmentPtr env)
|
||||
ASTNodePtr Eval::evalDef(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
{
|
||||
if (nodes.size() != 2) {
|
||||
Error::the().addError(format("wrong number of arguments: def!, {}", nodes.size()));
|
||||
Error::the().add(format("wrong number of arguments: def!, {}", nodes.size()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ ASTNodePtr Eval::evalDef(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
|
||||
// First element needs to be a Symbol
|
||||
if (!is<Symbol>(first_argument.get())) {
|
||||
Error::the().addError(format("wrong argument type: symbol, {}", first_argument));
|
||||
Error::the().add(format("wrong argument type: symbol, {}", first_argument));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ ASTNodePtr Eval::evalDef(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
ASTNodePtr Eval::evalLet(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
{
|
||||
if (nodes.size() != 2) {
|
||||
Error::the().addError(format("wrong number of arguments: let*, {}", nodes.size()));
|
||||
Error::the().add(format("wrong number of arguments: let*, {}", nodes.size()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ ASTNodePtr Eval::evalLet(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
|
||||
// First argument needs to be a List or Vector
|
||||
if (!is<Collection>(first_argument.get())) {
|
||||
Error::the().addError(format("wrong argument type: collection, '{}'", first_argument));
|
||||
Error::the().add(format("wrong argument type: collection, '{}'", first_argument));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ ASTNodePtr Eval::evalLet(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
// List or Vector needs to have an even number of elements
|
||||
size_t count = binding_nodes.size();
|
||||
if (count % 2 != 0) {
|
||||
Error::the().addError(format("wrong number of arguments: {}, {}", "let* bindings", count));
|
||||
Error::the().add(format("wrong number of arguments: {}, {}", "let* bindings", count));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ ASTNodePtr Eval::evalLet(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
for (auto it = binding_nodes.begin(); it != binding_nodes.end(); std::advance(it, 2)) {
|
||||
// First element needs to be a Symbol
|
||||
if (!is<Symbol>(*it->get())) {
|
||||
Error::the().addError(format("wrong argument type: symbol, '{}'", *it));
|
||||
Error::the().add(format("wrong argument type: symbol, '{}'", *it));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ ASTNodePtr Eval::evalLet(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
ASTNodePtr Eval::evalDo(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
{
|
||||
if (nodes.size() == 0) {
|
||||
Error::the().addError(format("wrong number of arguments: do, {}", nodes.size()));
|
||||
Error::the().add(format("wrong number of arguments: do, {}", nodes.size()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ ASTNodePtr Eval::evalDo(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
ASTNodePtr Eval::evalIf(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
{
|
||||
if (nodes.size() != 2 && nodes.size() != 3) {
|
||||
Error::the().addError(format("wrong number of arguments: if, {}", nodes.size()));
|
||||
Error::the().add(format("wrong number of arguments: if, {}", nodes.size()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -242,13 +242,13 @@ ASTNodePtr Eval::evalIf(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env)
|
||||
|
||||
#define ARG_COUNT_CHECK(name, size, comparison) \
|
||||
if (size comparison) { \
|
||||
Error::the().addError(format("wrong number of arguments: {}, {}", name, size)); \
|
||||
Error::the().add(format("wrong number of arguments: {}, {}", name, size)); \
|
||||
return nullptr; \
|
||||
}
|
||||
|
||||
#define AST_CHECK(type, value) \
|
||||
if (!is<type>(value.get())) { \
|
||||
Error::the().addError(format("wrong argument type: {}, {}", #type, value)); \
|
||||
Error::the().add(format("wrong argument type: {}, {}", #type, value)); \
|
||||
return nullptr; \
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ ASTNodePtr Eval::apply(std::shared_ptr<List> evaluated_list)
|
||||
auto nodes = evaluated_list->nodes();
|
||||
|
||||
if (!is<Function>(nodes.front().get()) && !is<Lambda>(nodes.front().get())) {
|
||||
Error::the().addError(format("invalid function: {}", nodes.front()));
|
||||
Error::the().add(format("invalid function: {}", nodes.front()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -27,7 +27,7 @@ void GlobalEnvironment::add()
|
||||
|
||||
for (auto node : nodes) {
|
||||
if (!is<Number>(node.get())) {
|
||||
Error::the().addError(format("wrong argument type: number, '{}'", node));
|
||||
Error::the().add(format("wrong argument type: number, '{}'", node));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void GlobalEnvironment::sub()
|
||||
|
||||
for (auto node : nodes) {
|
||||
if (!is<Number>(node.get())) {
|
||||
Error::the().addError(format("wrong argument type: number, '{}'", node));
|
||||
Error::the().add(format("wrong argument type: number, '{}'", node));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ void GlobalEnvironment::mul()
|
||||
|
||||
for (auto node : nodes) {
|
||||
if (!is<Number>(node.get())) {
|
||||
Error::the().addError(format("wrong argument type: number, '{}'", node));
|
||||
Error::the().add(format("wrong argument type: number, '{}'", node));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -92,13 +92,13 @@ void GlobalEnvironment::div()
|
||||
{
|
||||
auto div = [this](std::list<ASTNodePtr> nodes) -> ASTNodePtr {
|
||||
if (nodes.size() == 0) {
|
||||
Error::the().addError(format("wrong number of arguments: {}, 0", m_current_key));
|
||||
Error::the().add(format("wrong number of arguments: {}, 0", m_current_key));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto node : nodes) {
|
||||
if (!is<Number>(node.get())) {
|
||||
Error::the().addError(format("wrong argument type: number, '{}'", node));
|
||||
Error::the().add(format("wrong argument type: number, '{}'", node));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -124,13 +124,13 @@ void GlobalEnvironment::div()
|
||||
bool result = true; \
|
||||
\
|
||||
if (nodes.size() < 2) { \
|
||||
Error::the().addError(format("wrong number of arguments: {}, {}", m_current_key, nodes.size() - 1)); \
|
||||
Error::the().add(format("wrong number of arguments: {}, {}", m_current_key, nodes.size() - 1)); \
|
||||
return nullptr; \
|
||||
} \
|
||||
\
|
||||
for (auto node : nodes) { \
|
||||
if (!is<Number>(node.get())) { \
|
||||
Error::the().addError(format("wrong argument type: number, '{}'", node)); \
|
||||
Error::the().add(format("wrong argument type: number, '{}'", node)); \
|
||||
return nullptr; \
|
||||
} \
|
||||
} \
|
||||
@@ -181,7 +181,7 @@ void GlobalEnvironment::list()
|
||||
auto list = makePtr<List>();
|
||||
|
||||
for (auto node : nodes) {
|
||||
list->addNode(node);
|
||||
list->add(node);
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -215,7 +215,7 @@ void GlobalEnvironment::isEmpty()
|
||||
|
||||
for (auto node : nodes) {
|
||||
if (!is<Collection>(node.get())) {
|
||||
Error::the().addError(format("wrong argument type: collection, '{}'", node));
|
||||
Error::the().add(format("wrong argument type: collection, '{}'", node));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ void GlobalEnvironment::count()
|
||||
{
|
||||
auto count = [this](std::list<ASTNodePtr> nodes) -> ASTNodePtr {
|
||||
if (nodes.size() != 1) {
|
||||
Error::the().addError(format("wrong number of arguments: {}, {}", m_current_key, nodes.size() - 1));
|
||||
Error::the().add(format("wrong number of arguments: {}, {}", m_current_key, nodes.size() - 1));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ void GlobalEnvironment::count()
|
||||
result = std::static_pointer_cast<Collection>(first_argument)->size();
|
||||
}
|
||||
else {
|
||||
Error::the().addError(format("wrong argument type: collection, '{}'", first_argument));
|
||||
Error::the().add(format("wrong argument type: collection, '{}'", first_argument));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ void GlobalEnvironment::equal()
|
||||
{
|
||||
auto lambda = [this](std::list<ASTNodePtr> nodes) -> ASTNodePtr {
|
||||
if (nodes.size() < 2) {
|
||||
Error::the().addError(format("wrong number of arguments: {}, {}", m_current_key, nodes.size() - 1));
|
||||
Error::the().add(format("wrong number of arguments: {}, {}", m_current_key, nodes.size() - 1));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ bool Lexer::consumeString()
|
||||
}
|
||||
|
||||
if (character != '"') {
|
||||
Error::the().addError({ Token::Type::Error, m_line, column, "expected '\"', got EOF" });
|
||||
Error::the().add({ Token::Type::Error, m_line, column, "expected '\"', got EOF" });
|
||||
}
|
||||
|
||||
m_tokens.push_back({ Token::Type::String, m_line, column, text });
|
||||
|
||||
+30
-30
@@ -50,7 +50,7 @@ void Reader::read()
|
||||
case Token::Type::Comment:
|
||||
break;
|
||||
default:
|
||||
Error::the().addError("more than one sexp in input");
|
||||
Error::the().add("more than one sexp in input");
|
||||
break;
|
||||
};
|
||||
}
|
||||
@@ -70,21 +70,21 @@ ASTNodePtr Reader::readImpl()
|
||||
return readList();
|
||||
break;
|
||||
case Token::Type::ParenClose: // )
|
||||
Error::the().addError("invalid read syntax: ')'");
|
||||
Error::the().add("invalid read syntax: ')'");
|
||||
return nullptr;
|
||||
break;
|
||||
case Token::Type::BracketOpen: // [
|
||||
return readVector();
|
||||
break;
|
||||
case Token::Type::BracketClose: // ]
|
||||
Error::the().addError("invalid read syntax: ']'");
|
||||
Error::the().add("invalid read syntax: ']'");
|
||||
return nullptr;
|
||||
break;
|
||||
case Token::Type::BraceOpen: // {
|
||||
return readHashMap();
|
||||
break;
|
||||
case Token::Type::BraceClose: // }
|
||||
Error::the().addError("invalid read syntax: '}'");
|
||||
Error::the().add("invalid read syntax: '}'");
|
||||
return nullptr;
|
||||
break;
|
||||
case Token::Type::Quote: // '
|
||||
@@ -129,13 +129,13 @@ ASTNodePtr Reader::readSpliceUnquote()
|
||||
ignore(); // ~@
|
||||
|
||||
if (isEOF()) {
|
||||
Error::the().addError("expected form, got EOF");
|
||||
Error::the().add("expected form, got EOF");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto list = makePtr<List>();
|
||||
list->addNode(makePtr<Symbol>("splice-unquote"));
|
||||
list->addNode(readImpl());
|
||||
list->add(makePtr<Symbol>("splice-unquote"));
|
||||
list->add(readImpl());
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -146,11 +146,11 @@ ASTNodePtr Reader::readList()
|
||||
|
||||
auto list = makePtr<List>();
|
||||
while (!isEOF() && peek().type != Token::Type::ParenClose) {
|
||||
list->addNode(readImpl());
|
||||
list->add(readImpl());
|
||||
}
|
||||
|
||||
if (!consumeSpecific(Token { .type = Token::Type::ParenClose })) { // )
|
||||
Error::the().addError("expected ')', got EOF");
|
||||
Error::the().add("expected ')', got EOF");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -163,11 +163,11 @@ ASTNodePtr Reader::readVector()
|
||||
|
||||
auto vector = makePtr<Vector>();
|
||||
while (!isEOF() && peek().type != Token::Type::BracketClose) {
|
||||
vector->addNode(readImpl());
|
||||
vector->add(readImpl());
|
||||
}
|
||||
|
||||
if (!consumeSpecific(Token { .type = Token::Type::BracketClose })) { // ]
|
||||
Error::the().addError("expected ']', got EOF");
|
||||
Error::the().add("expected ']', got EOF");
|
||||
}
|
||||
|
||||
return vector;
|
||||
@@ -187,12 +187,12 @@ ASTNodePtr Reader::readHashMap()
|
||||
}
|
||||
|
||||
if (key == nullptr || value == nullptr) {
|
||||
Error::the().addError("hash-map requires an even-sized list");
|
||||
Error::the().add("hash-map requires an even-sized list");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!is<String>(key.get()) && !is<Keyword>(key.get())) {
|
||||
Error::the().addError(format("{} is not a string or keyword", key));
|
||||
Error::the().add(format("{} is not a string or keyword", key));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ ASTNodePtr Reader::readHashMap()
|
||||
}
|
||||
|
||||
if (!consumeSpecific(Token { .type = Token::Type::BraceClose })) { // }
|
||||
Error::the().addError("expected '}', got EOF");
|
||||
Error::the().add("expected '}', got EOF");
|
||||
}
|
||||
|
||||
return hash_map;
|
||||
@@ -212,13 +212,13 @@ ASTNodePtr Reader::readQuote()
|
||||
ignore(); // '
|
||||
|
||||
if (isEOF()) {
|
||||
Error::the().addError("expected form, got EOF");
|
||||
Error::the().add("expected form, got EOF");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto list = makePtr<List>();
|
||||
list->addNode(makePtr<Symbol>("quote"));
|
||||
list->addNode(readImpl());
|
||||
list->add(makePtr<Symbol>("quote"));
|
||||
list->add(readImpl());
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -228,13 +228,13 @@ ASTNodePtr Reader::readQuasiQuote()
|
||||
ignore(); // `
|
||||
|
||||
if (isEOF()) {
|
||||
Error::the().addError("expected form, got EOF");
|
||||
Error::the().add("expected form, got EOF");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto list = makePtr<List>();
|
||||
list->addNode(makePtr<Symbol>("quasiquote"));
|
||||
list->addNode(readImpl());
|
||||
list->add(makePtr<Symbol>("quasiquote"));
|
||||
list->add(readImpl());
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -244,13 +244,13 @@ ASTNodePtr Reader::readUnquote()
|
||||
ignore(); // ~
|
||||
|
||||
if (isEOF()) {
|
||||
Error::the().addError("expected form, got EOF");
|
||||
Error::the().add("expected form, got EOF");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto list = makePtr<List>();
|
||||
list->addNode(makePtr<Symbol>("unquote"));
|
||||
list->addNode(readImpl());
|
||||
list->add(makePtr<Symbol>("unquote"));
|
||||
list->add(readImpl());
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -261,17 +261,17 @@ ASTNodePtr Reader::readWithMeta()
|
||||
|
||||
ignore(); // first token
|
||||
if (isEOF()) { // second token
|
||||
Error::the().addError("expected form, got EOF");
|
||||
Error::the().add("expected form, got EOF");
|
||||
return nullptr;
|
||||
}
|
||||
retreat();
|
||||
|
||||
auto list = makePtr<List>();
|
||||
list->addNode(makePtr<Symbol>("with-meta"));
|
||||
list->add(makePtr<Symbol>("with-meta"));
|
||||
ASTNodePtr first = readImpl();
|
||||
ASTNodePtr second = readImpl();
|
||||
list->addNode(second);
|
||||
list->addNode(first);
|
||||
list->add(second);
|
||||
list->add(first);
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -281,13 +281,13 @@ ASTNodePtr Reader::readDeref()
|
||||
ignore(); // @
|
||||
|
||||
if (isEOF()) {
|
||||
Error::the().addError("expected form, got EOF");
|
||||
Error::the().add("expected form, got EOF");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto list = makePtr<List>();
|
||||
list->addNode(makePtr<Symbol>("deref"));
|
||||
list->addNode(readImpl());
|
||||
list->add(makePtr<Symbol>("deref"));
|
||||
list->add(readImpl());
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user