feat: error handling, better prelude, double linked lists usage etc
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <cassert>
|
||||
#include "parser/lexer.hpp"
|
||||
#include "parser/nodes.hpp"
|
||||
#include "prelude/error.hpp"
|
||||
|
||||
class AstParser
|
||||
{
|
||||
@@ -78,8 +79,8 @@ public:
|
||||
return new VariableNode(name);
|
||||
}
|
||||
default:
|
||||
fprintf(stderr, "%s:%d:%d: ERROR: unexpected token while parsing %ld\n", m_lexer->filename(), token->line_number, token->offset_start, token->token);
|
||||
Exit(1);
|
||||
// fprintf(stderr, "%s:%d:%d: ERROR: unexpected token while parsing %ld\n", m_lexer->filename(), token->line_number, token->offset_start, token->token);
|
||||
ErrorLogger::Raise(Error::ParseError(m_lexer->filename(), StringView::FromFormat("unexpected token while parsing '%c'", token->token), token->line_number, token->offset_start));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -94,7 +95,7 @@ public:
|
||||
{
|
||||
m_lexer->NextToken();
|
||||
ExpressionNode::Operator eop;
|
||||
assert((int)ExpressionNode::Operator::COUNT_OPERATORS == 4 && "some operators may not be handled");
|
||||
assert(static_cast<size_t>(ExpressionNode::Operator::COUNT_OPERATORS) == 4 && "some operators may not be handled");
|
||||
switch((char)op->token)
|
||||
{
|
||||
case '/':
|
||||
@@ -122,7 +123,7 @@ public:
|
||||
{
|
||||
m_lexer->NextToken();
|
||||
ExpressionNode::Operator eop;
|
||||
assert((int)ExpressionNode::Operator::COUNT_OPERATORS == 4 && "some operators may not be handled");
|
||||
assert(static_cast<size_t>(ExpressionNode::Operator::COUNT_OPERATORS) == 4 && "some operators may not be handled");
|
||||
switch((char)op->token)
|
||||
{
|
||||
case '+':
|
||||
@@ -155,8 +156,7 @@ public:
|
||||
Node* ParseStatement()
|
||||
{
|
||||
auto token = m_lexer->seek_token();
|
||||
// TODO: proper error handling
|
||||
assert(token != nullptr && "next token should be available");
|
||||
assert(token != nullptr);
|
||||
switch(token->token)
|
||||
{
|
||||
case TokenType::Local: return ParseVarDecl();
|
||||
@@ -176,13 +176,13 @@ public:
|
||||
auto token = m_lexer->token();
|
||||
switch(token.token)
|
||||
{
|
||||
case TokenType::Extern: program->PushExtern(ParseExtern()); break;
|
||||
case TokenType::Fn: program->PushFunction(ParseFnDecl()); break;
|
||||
case TokenType::Extern: program->PushExtern(ParseExtern()); break;
|
||||
default: {
|
||||
fprintf(stderr, "%s:%d:%d: ERROR: unexpected token while parsing %ld\n", m_lexer->filename(), token.line_number, token.offset_start, token.token);
|
||||
Exit(1);
|
||||
break;
|
||||
ErrorLogger::Raise(Error::ParseError(m_lexer->filename(), StringView::FromFormat("unexpected token while parsing '%c'", token.token), token.line_number, token.offset_start));
|
||||
assert(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user