refactor(parser): change body_h to body result

Refs: #1
This commit is contained in:
2026-06-03 10:45:57 +02:00
parent 6ce2fba9d2
commit 26340c279d
7 changed files with 45 additions and 20 deletions
+3 -3
View File
@@ -95,7 +95,7 @@ public:
* @param name Name of the function.
* @param body Body of the function.
*/
function_definition_node(front::token name, body_h&& body)
function_definition_node(front::token name, body_r&& body)
: function_declaration_node(name), m_body(std::move(body)) {}
public:
/**
@@ -110,7 +110,7 @@ public:
*
* @return Body of the function.
*/
const body_h& body() const { return m_body; }
const body_r& body() const { return m_body; }
public:
void accept(visitor& visitor) const override;
@@ -118,7 +118,7 @@ public:
protected:
bool equal(const node& rhs) const override;
private:
body_h m_body;
body_r m_body;
};
} // namespace ast
+26 -1
View File
@@ -1,7 +1,9 @@
#ifndef FURC_AST_FWD_HPP
#define FURC_AST_FWD_HPP
#include "furc/diag.hpp"
#include "furc/handle.hpp"
#include "furlang/result.hpp"
#include <string>
#include <vector>
@@ -13,6 +15,29 @@ namespace furc {
*/
namespace ast {
/**
* @brief AST error.
*/
struct error {
location location; /**< Location of the error. */
/**
* @brief Compares two AST errors for equality.
*
* @param other Error to compare against.
* @return true if the errors are equal.
*/
bool operator==(const error& other) const { return location == other.location; }
/**
* @brief Compares two AST errors for inequality.
*
* @param other Error to compare against.
* @return true if the errors are not equal.
*/
bool operator!=(const error& other) const { return !this->operator==(other); }
};
class node;
/**
@@ -162,7 +187,7 @@ struct body {
* @brief Alias for body result.
* @see body
*/
using body_h = handle<body>;
using body_r = furlang::result<body, error>;
class function_declaration_node;
+3 -3
View File
@@ -150,7 +150,7 @@ public:
*
* @param body Body handle.
*/
compound_statement_node(body_h&& body)
compound_statement_node(body_r&& body)
: m_body(std::move(body)) {}
public:
/**
@@ -158,7 +158,7 @@ public:
*
* @return The body handle.
*/
const body_h& body() const { return m_body; }
const body_r& body() const { return m_body; }
public:
/**
* @brief Returns this node's statement type.
@@ -173,7 +173,7 @@ public:
protected:
bool equal(const node& rhs) const override;
private:
body_h m_body; /**< The body handle. */
body_r m_body; /**< The body handle. */
};
} // namespace ast
+1 -1
View File
@@ -65,7 +65,7 @@ private:
ast::expression_node_h parse_expression_unary(std::uint32_t precedence);
ast::expression_node_h parse_expression_rhs(ast::expression_node_h&& init, std::uint32_t precedence);
ast::body_h parse_body();
ast::body_r parse_body();
private:
static ast::node_handle<ast::node> error_handle(const token_r& result);
private: