6 #ifndef GDCORE_EXPRESSIONNODEPRINTER_H
7 #define GDCORE_EXPRESSIONNODEPRINTER_H
12 #include "GDCore/Events/Parsers/ExpressionParser2Node.h"
13 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h"
16 class ObjectsContainer;
18 class ParameterMetadata;
19 class ExpressionMetadata;
53 void OnVisitSubExpressionNode(SubExpressionNode& node)
override {
55 node.expression->Visit(*
this);
58 void OnVisitOperatorNode(OperatorNode& node)
override {
59 node.leftHandSide->Visit(*
this);
70 node.rightHandSide->Visit(*
this);
72 void OnVisitUnaryOperatorNode(UnaryOperatorNode& node)
override {
73 output.push_back(node.op);
74 node.factor->Visit(*
this);
76 void OnVisitNumberNode(NumberNode& node)
override { output += node.number; }
77 void OnVisitTextNode(TextNode& node)
override {
78 output += PrintStringLiteral(node.text);
80 void OnVisitVariableNode(VariableNode& node)
override {
82 if (node.child) node.child->Visit(*
this);
84 void OnVisitVariableAccessorNode(VariableAccessorNode& node)
override {
85 output +=
"." + node.name;
86 if (node.child) node.child->Visit(*
this);
88 void OnVisitVariableBracketAccessorNode(
89 VariableBracketAccessorNode& node)
override {
91 node.expression->Visit(*
this);
93 if (node.child) node.child->Visit(*
this);
95 void OnVisitIdentifierNode(IdentifierNode& node)
override {
96 output += node.identifierName;
97 if (!node.childIdentifierName.empty()) {
98 output +=
"." + node.childIdentifierName;
101 void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node)
override {
102 if (!node.behaviorFunctionName.empty()) {
103 output += node.objectName +
"." + node.objectFunctionOrBehaviorName +
104 "::" + node.behaviorFunctionName;
106 output += node.objectName +
"." + node.objectFunctionOrBehaviorName;
109 void OnVisitFunctionCallNode(FunctionCallNode& node)
override {
110 if (!node.behaviorName.empty()) {
112 node.objectName +
"." + node.behaviorName +
"::" + node.functionName;
113 }
else if (!node.objectName.empty()) {
114 output += node.objectName +
"." + node.functionName;
116 output += node.functionName;
122 for (
auto& parameterNode : node.parameters) {
123 if (!isFirst) output +=
", ";
124 parameterNode->Visit(*
this);
130 void OnVisitEmptyNode(EmptyNode& node)
override { output += node.text; }
Print the expression corresponding to a set of nodes (i.e: this is doing the inverse operation of gd:...
Definition: ExpressionParser2NodePrinter.h:31
const gd::String & GetOutput()
Get the string corresponding to the expression nodes.
Definition: ExpressionParser2NodePrinter.h:45
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
String represents an UTF8 encoded string.
Definition: String.h:33
void push_back(value_type character)
Add a character (from its codepoint) at the end of the String.
Definition: String.cpp:223
String FindAndReplace(String search, String replacement, bool all=true) const
Searches a string for a specified substring and returns a new string where all occurrences of this su...
Definition: String.cpp:413
Definition: CommonTools.h:24
The base node, from which all nodes in the tree of an expression inherits from.
Definition: ExpressionParser2Node.h:100