-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include "node.hpp" | ||
#include "../value.hpp" | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
namespace rift { | ||
|
||
/// @brief A node in the AST that should be evaluated as a sub-expression. (used for sub-string interpolation) | ||
class ExecuteNode : public Node { | ||
public: | ||
/// @brief Construct the execute node. | ||
/// @param child The child node to execute. | ||
explicit ExecuteNode(Node* child) : m_child(child) {} | ||
|
||
~ExecuteNode() override { | ||
delete m_child; | ||
} | ||
|
||
/// @brief Get the child node to execute. | ||
/// @return The child node to execute. | ||
[[nodiscard]] const Node* getChild() const { return m_child; } | ||
|
||
/// @copydoc Node::getType | ||
[[nodiscard]] Type getType() const override { return Type::Execute; } | ||
|
||
/// @copydoc Node::accept | ||
void accept(Visitor* visitor) override; | ||
|
||
/// @copydoc Node::getValue | ||
[[nodiscard]] Value getValue(Visitor* visitor) const override; | ||
|
||
/// @copydoc Node::print | ||
std::ostream& print(std::ostream& out) const override { | ||
out << "ExecuteNode(" << *m_child << ')'; | ||
return out; | ||
} | ||
|
||
private: | ||
Node* m_child; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ namespace rift { | |
BinaryOp, | ||
FunctionCall, | ||
TernaryOp, | ||
Execute | ||
}; | ||
|
||
/// @brief Destruct the node. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <rift/nodes/execute.hpp> | ||
#include <rift/visitor.hpp> | ||
|
||
namespace rift { | ||
|
||
void ExecuteNode::accept(Visitor* visitor) { | ||
visitor->visit(this); | ||
} | ||
|
||
Value ExecuteNode::getValue(Visitor* visitor) const { | ||
auto value = m_child->getValue(visitor); | ||
if (value.isString()) { | ||
return Value::from(rift::format(value.getString(), *visitor->getVariables())); | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters