Add default constructor to handle

Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
CHatingPython
2026-05-26 12:30:01 +02:00
committed by CHatingPython
parent ad84bc50bd
commit 7017d83204
8 changed files with 172 additions and 81 deletions
+45
View File
@@ -0,0 +1,45 @@
#include "furc/ast/declaration.hpp"
#include "furc/ast/literal.hpp"
#include "furc/ast/node.hpp"
#include "furc/ast/program.hpp"
#include "furc/ast/statement.hpp"
#include <ostream>
namespace furc::ast {
std::ostream& integer_literal_node::print(std::ostream& os) const {
if (m_value.has_error()) return os << m_value.error();
return os << "integer literal (" << *m_value << ")";
}
std::ostream& function_declarartion_node::print(std::ostream& os) const {
return os << "function " << m_name->string << " declaration";
}
std::ostream& function_definition_node::print(std::ostream& os) const {
function_declarartion_node::print(os);
os << ':';
if (m_body.present()) {
for (const auto& entry : m_body->statements)
os << '\n' << entry;
return os << '\n' << m_body->end << ": " << m_name->string << " end";
}
return os << m_body.error(); // error
}
std::ostream& return_statement_node::print(std::ostream& os) const {
os << "return statement";
if (m_value.present()) return os << " (" << *m_value << ')';
return os;
}
std::ostream& program_node::print(std::ostream& os) const {
os << "program:";
for (const auto& handle : m_declarations) {
os << '\n' << handle;
}
return os;
}
} // namespace furc::ast
+9 -4
View File
@@ -93,11 +93,16 @@ ast::node_handle<ast::statement_node> parser::parse_statement() {
if (tok.has_error()) return tok;
switch (tok->type) {
case token_t::Keyword: {
next_token();
auto err = eat_token(token_t::Semicolon);
if (err.has_error()) return err;
auto tok = next_token();
if (peek_token()->type == token_t::Semicolon) {
next_token();
return ast::node_handle<ast::return_statement_node>{ tok.location(), m_arena };
}
return ast::node_handle<ast::return_statement_node>{ tok.location(), m_arena };
auto value = parse_expression();
auto err = eat_token(token_t::Semicolon);
if (err.has_error()) return err;
return ast::node_handle<ast::return_statement_node>{ tok.location(), m_arena, std::move(value) };
}
default: break;
}
+1 -1
View File
@@ -5,7 +5,7 @@
#include <iostream>
int main(void) {
furc::front::parser parser("<TEMP>", "func main() {\n return;\n}");
furc::front::parser parser("<TEMP>", "func main() {\n return 67;return \"uwu\";\n}");
std::cout << parser.parse() << '\n';
return 0;