26 std::unordered_map<std::string, Node> args_applied;
28 for (std::size_t i = 1, end = node.
constList().size(); i < end; ++i)
30 const std::string& arg_name = args.
list()[j].string();
33 args_applied[arg_name] = node.
constList()[i];
38 if (args_applied.find(arg_name) == args_applied.end())
44 args_applied[arg_name].push_back(node.
constList()[i]);
55 else if (args_applied.size() != args.
list().size())
57 std::size_t args_needed = args.
list().size();
58 std::string macro_name = macro->
constList()[0].string();
61 throwMacroProcessingError(
"Macro `" + macro_name +
"' got " + std::to_string(args_applied.size()) +
" argument(s) but needed " + std::to_string(args_needed), *macro);
63 throwMacroProcessingError(
"Macro `" + macro_name +
"' got " + std::to_string(args_applied.size()) +
" argument(s) but needed at least " + std::to_string(args_needed - 1), *macro);
66 if (!args_applied.empty())
67 unify(args_applied, temp_body,
nullptr);
Executor for List Macros.
bool applyMacro(Node &node) override
Executes macros in the Node if the Executor can handle it.
bool canHandle(Node &node) override
Checks if the executor can apply a macro on the passed Node.
Node evaluate(Node &node, bool is_not_body)
Evaluate only the macros.
void throwMacroProcessingError(const std::string &message, const Node &node)
Throw a macro processing error.
Node * findNearestMacro(const std::string &name)
Find the nearest macro matching a giving name.
void unify(const std::unordered_map< std::string, Node > &, Node &, Node *)
Applies the spread operator.
bool isPredefined(const std::string &symbol)
Check if a given symbol is a predefined macro.
bool applyMacroProxy(Node &node)
Execute a node, trying to emplace macros calls.
A node of an Abstract Syntax Tree for ArkScript.
NodeType nodeType() const noexcept
Return the node type.
static const Node & getListNode()
Provide a statically initialized / correct and guaranteed to be initialized Node representing "Empty ...
const std::string & string() const noexcept
Return the string held by the value (if the node type allows it)
const std::vector< Node > & constList() const noexcept
Return the list of sub-nodes held by the node.
std::vector< Node > & list() noexcept
Return the list of sub-nodes held by the node.