feat: introduce parse type function

Refs: #15
This commit is contained in:
2026-06-24 15:30:45 +02:00
parent b5dcd6690a
commit 70b7b6a2f4
2 changed files with 11 additions and 0 deletions
+3
View File
@@ -1,6 +1,7 @@
#ifndef FURC_FRONT_PARSER_HPP #ifndef FURC_FRONT_PARSER_HPP
#define FURC_FRONT_PARSER_HPP #define FURC_FRONT_PARSER_HPP
#include "furc/ast/declaration.hpp"
#include "furc/ast/fwd.hpp" #include "furc/ast/fwd.hpp"
#include "furc/front/lexer.hpp" #include "furc/front/lexer.hpp"
#include "furlang/arena.hpp" #include "furlang/arena.hpp"
@@ -56,6 +57,8 @@ public:
*/ */
ast::program_node_r parse() &; ast::program_node_r parse() &;
private: private:
ast::type_r parse_type();
ast::declaration_node_r parse_declaration(); ast::declaration_node_r parse_declaration();
ast::statement_node_r parse_statement(); ast::statement_node_r parse_statement();
ast::expression_node_r parse_expression(std::uint32_t precedence = 16); ast::expression_node_r parse_expression(std::uint32_t precedence = 16);
+8
View File
@@ -6,6 +6,7 @@
#include "furc/ast/literal.hpp" // IWYU pragma: keep #include "furc/ast/literal.hpp" // IWYU pragma: keep
#include "furc/ast/program.hpp" // IWYU pragma: keep #include "furc/ast/program.hpp" // IWYU pragma: keep
#include "furc/ast/statement.hpp" // IWYU pragma: keep #include "furc/ast/statement.hpp" // IWYU pragma: keep
#include "furc/front/token.hpp"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@@ -46,6 +47,13 @@ ast::program_node_r parser::parse() & {
return program != nullptr ? std::move(program) : ast::program_node_r(ast::error{ location{ m_filename } }); return program != nullptr ? std::move(program) : ast::program_node_r(ast::error{ location{ m_filename } });
} }
ast::type_r parser::parse_type() {
auto token = eat_token(token_t::Keyword);
if (token.has_error() || token.value()->keyword != keyword_token::Int32)
return ast::type_r(ast::error{ token.error().location });
return ast::type("" + token.value()->keyword);
}
ast::declaration_node_r parser::parse_declaration() { ast::declaration_node_r parser::parse_declaration() {
const auto& first = peek_token(); const auto& first = peek_token();
switch (first->type) { switch (first->type) {