6 #ifndef GDCORE_EXPRESSIONNODELOCATIONFINDER_H
7 #define GDCORE_EXPRESSIONNODELOCATIONFINDER_H
12 #include "GDCore/Events/Parsers/ExpressionParser2Node.h"
13 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h"
16 class ObjectsContainer;
18 class ParameterMetadata;
19 class ExpressionMetadata;
36 : searchedPosition(searchedPosition_), foundNode(nullptr){};
44 size_t searchedPosition) {
57 size_t searchedPosition) {
76 CheckSearchPositionInNode(node);
77 node.expression->Visit(*
this);
79 void OnVisitOperatorNode(OperatorNode& node)
override {
80 if (CheckSearchPositionInNode(node)) {
81 node.leftHandSide->Visit(*
this);
82 node.rightHandSide->Visit(*
this);
85 void OnVisitUnaryOperatorNode(UnaryOperatorNode& node)
override {
86 CheckSearchPositionInNode(node);
87 node.factor->Visit(*
this);
89 void OnVisitNumberNode(NumberNode& node)
override {
90 CheckSearchPositionInNode(node);
92 void OnVisitTextNode(TextNode& node)
override {
93 CheckSearchPositionInNode(node);
95 void OnVisitVariableNode(VariableNode& node)
override {
96 if (CheckSearchPositionInNode(node)) {
97 if (node.child) node.child->Visit(*
this);
100 void OnVisitVariableAccessorNode(VariableAccessorNode& node)
override {
101 if (CheckSearchPositionInNode(node)) {
102 if (node.child) node.child->Visit(*
this);
105 void OnVisitVariableBracketAccessorNode(
106 VariableBracketAccessorNode& node)
override {
107 if (CheckSearchPositionInNode(node)) {
108 node.expression->Visit(*
this);
109 if (node.child) node.child->Visit(*
this);
112 void OnVisitIdentifierNode(IdentifierNode& node)
override {
113 CheckSearchPositionInNode(node);
115 void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node)
override {
116 CheckSearchPositionInNode(node);
118 void OnVisitFunctionCallNode(FunctionCallNode& node)
override {
119 CheckSearchPositionInNode(node);
120 for (
auto& parameter : node.parameters) {
121 parameter->Visit(*
this);
124 void OnVisitEmptyNode(EmptyNode& node)
override {
125 CheckSearchPositionInNode(node,
true);
129 bool CheckSearchPositionInNode(ExpressionNode& node,
bool inclusive =
false) {
130 if (node.location.GetStartPosition() <= searchedPosition &&
131 ((!inclusive && searchedPosition < node.location.GetEndPosition()) ||
132 (inclusive && searchedPosition <= node.location.GetEndPosition()))) {
133 parentNode = foundNode;
141 size_t searchedPosition;
142 ExpressionNode* foundNode;
143 ExpressionNode* parentNode;
Find the deepest node at the specified location in an expression.
Definition: ExpressionNodeLocationFinder.h:30
static ExpressionNode * GetParentNodeAtPosition(gd::ExpressionNode &node, size_t searchedPosition)
Helper function to find the parent of the deepest node at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:56
ExpressionNode * GetParentNode()
Return the parent of deepest node found at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:72
ExpressionNode * GetNode()
Return the deepest node found at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:66
ExpressionNodeLocationFinder(size_t searchedPosition_)
Initialize the finder to search at the specified position.
Definition: ExpressionNodeLocationFinder.h:35
static ExpressionNode * GetNodeAtPosition(gd::ExpressionNode &node, size_t searchedPosition)
Helper function to find the deepest node at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:43
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
Definition: CommonTools.h:24
The base node, from which all nodes in the tree of an expression inherits from.
Definition: ExpressionParser2Node.h:93
Definition: ExpressionParser2Node.h:108