#ifndef MACRODOWN_MACRO_ENGINE_H
#define MACRODOWN_MACRO_ENGINE_H
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <functional>
#include "nodes.h"
namespace macrodown
{
using MacroCallback = std::function<std::string(const std::vector<std::string>&)>;
struct MacroDefinition
{
std::string name;
std::vector<std::string> arg_names;
std::string body; // Raw body for user-defined macros
MacroCallback callback; // For intrinsic macros
bool is_intrinsic = false;
MacroDefinition() = default;
// For user-defined macros
MacroDefinition(std::string n, std::vector<std::string> args, std::string b)
: name(std::move(n)), arg_names(std::move(args)), body(std::move(b)), is_intrinsic(false) {}
// For intrinsic macros
MacroDefinition(std::string n, MacroCallback cb)
: name(std::move(n)), callback(std::move(cb)), is_intrinsic(true) {}
};
class Evaluator
{
public:
Evaluator();
void define(const std::string& name, const std::vector<std::string>& args, const std::string& body);
void defineIntrinsic(const std::string& name, MacroCallback callback);
std::string evaluate(const Node& node);
std::string evaluateMacro(const Macro& macro);
private:
std::map<std::string, MacroDefinition> macros_;
};
} // namespace macrodown
#endif // MACRODOWN_MACRO_ENGINE_H