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