can now parse prefix expressions!
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "token/token.hpp"
|
||||
#include "token/type.hpp"
|
||||
|
||||
namespace ast::error {
|
||||
@@ -12,6 +13,14 @@ namespace ast::error {
|
||||
explicit parser_error(const std::string& message): error(message) {}
|
||||
};
|
||||
|
||||
struct unkown_prefix : parser_error {
|
||||
token::token prefix;
|
||||
|
||||
explicit unkown_prefix(token::token prefix, const std::string& message)
|
||||
: parser_error(message),
|
||||
prefix(prefix) {}
|
||||
};
|
||||
|
||||
struct expected_next : parser_error {
|
||||
token::type expected_type;
|
||||
|
||||
|
19
src/ast/expressions/prefix.cpp
Normal file
19
src/ast/expressions/prefix.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "prefix.hpp"
|
||||
|
||||
#include "token/token.hpp"
|
||||
|
||||
namespace ast {
|
||||
|
||||
prefix_expr::prefix_expr(token::token token, std::string op)
|
||||
: token(std::move(token)),
|
||||
op(op),
|
||||
right(nullptr) {}
|
||||
|
||||
std::string prefix_expr::token_literal() const {
|
||||
return token.literal;
|
||||
}
|
||||
|
||||
std::string prefix_expr::str() const {
|
||||
return token.literal + right->str();
|
||||
}
|
||||
} // namespace ast
|
16
src/ast/expressions/prefix.hpp
Normal file
16
src/ast/expressions/prefix.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "ast/ast.hpp"
|
||||
#include "token/token.hpp"
|
||||
|
||||
namespace ast {
|
||||
struct prefix_expr : expression {
|
||||
prefix_expr(token::token token, std::string op);
|
||||
token::token token;
|
||||
std::string op;
|
||||
expression* right;
|
||||
|
||||
std::string token_literal() const override;
|
||||
std::string str() const override;
|
||||
};
|
||||
} // namespace ast
|
Reference in New Issue
Block a user