diff --git a/src/ast.cpp b/src/ast.cpp index 437106f..47da97e 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -8,6 +8,7 @@ #include #include "ast.h" +#include "types.h" namespace blaze { @@ -59,3 +60,25 @@ Value::Value(const std::string& value) } } // namespace blaze + +// ----------------------------------------- + +void Formatter::format(Builder& builder, blaze::ASTNode* value) const +{ + if (is(value)) { + return Formatter::format(builder, static_cast(value)->data()); + } + if (is(value)) { + return Formatter::format(builder, ":" + static_cast(value)->keyword().substr(1)); + } + else if (is(value)) { + Formatter formatter { .specifier = specifier }; + return formatter.format(builder, static_cast(value)->number()); + } + else if (is(value)) { + return Formatter::format(builder, static_cast(value)->value()); + } + else if (is(value)) { + return Formatter::format(builder, static_cast(value)->symbol()); + } +} diff --git a/src/ast.h b/src/ast.h index f626cb7..cafa549 100644 --- a/src/ast.h +++ b/src/ast.h @@ -12,6 +12,8 @@ #include // typeid #include +#include "ruc/format/formatter.h" + namespace blaze { class ASTNode { @@ -205,3 +207,10 @@ inline bool ASTNode::fastIs() const { return isValue(); } // clang-format on } // namespace blaze + +// ----------------------------------------- + +template<> +struct ruc::format::Formatter : public Formatter { + void format(Builder& builder, blaze::ASTNode* value) const; +};