16#ifndef QGSESRIARCADESCRIPT_H
17#define QGSESRIARCADESCRIPT_H
24#include <QCoreApplication>
31using namespace Qt::StringLiterals;
63 switch ( sipCpp->nodeType() )
66 sipType = sipType_QgsEsriArcadeBlockStatement;
69 sipType = sipType_QgsEsriArcadeVariableDeclarationStatement;
72 sipType = sipType_QgsEsriArcadeAssignmentStatement;
75 sipType = sipType_QgsEsriArcadeReturnStatement;
78 sipType = sipType_QgsEsriArcadeFunctionDeclarationStatement;
81 sipType = sipType_QgsEsriArcadeExpressionStatement;
84 sipType = sipType_QgsEsriArcadeArrayLiteralExpression;
87 sipType = sipType_QgsEsriArcadeLiteralExpression;
90 sipType = sipType_QgsEsriArcadeVariableReferenceExpression;
93 sipType = sipType_QgsEsriArcadeProfileVariableReferenceExpression;
96 sipType = sipType_QgsEsriArcadeMemberAccessExpression;
99 sipType = sipType_QgsEsriArcadeBinaryOperatorExpression;
102 sipType = sipType_QgsEsriArcadeUnaryOperatorExpression;
105 sipType = sipType_QgsEsriArcadeFunctionCallExpression;
108 sipType = sipType_QgsEsriArcadeIndexExpression;
111 sipType = sipType_QgsEsriArcadeDictionaryLiteralExpression;
114 sipType = sipType_QgsEsriArcadeIfStatement;
117 sipType = sipType_QgsEsriArcadeForStatement;
120 sipType = sipType_QgsEsriArcadeForInStatement;
123 sipType = sipType_QgsEsriArcadeWhileStatement;
126 sipType = sipType_QgsEsriArcadeBreakStatement;
129 sipType = sipType_QgsEsriArcadeContinueStatement;
145 VariableDeclarationStatement,
148 FunctionDeclarationStatement,
151 VariableReferenceExpression,
152 ProfileVariableReferenceExpression,
153 MemberAccessExpression,
154 BinaryOperatorExpression,
155 UnaryOperatorExpression,
156 FunctionCallExpression,
158 ArrayLiteralExpression,
159 DictionaryLiteralExpression,
180 virtual QString
dump()
const = 0;
249 QString dump()
const override;
268 int count()
const {
return mStatements.count(); }
278 QList<QgsEsriArcadeStatement *> mStatements;
300 QString dump()
const override;
327 QString mVariableName;
328 std::unique_ptr<QgsEsriArcadeExpression> mInitializer;
355 static const char *ASSIGNMENT_OPERATOR_TEXT[]
SIP_SKIP;
365 QString dump()
const override;
392 std::unique_ptr<QgsEsriArcadeExpression> mTarget;
393 std::unique_ptr<QgsEsriArcadeExpression> mValue;
394 AssignmentOperator mAssignmentOperator = AssignmentOperator::Assign;
416 QString dump()
const override;
433 std::unique_ptr<QgsEsriArcadeExpression> mExpression;
455 QString dump()
const override;
482 QString mFunctionName;
483 QStringList mParameters;
484 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
508 QString dump()
const override;
525 std::unique_ptr<QgsEsriArcadeExpression> mExpression;
543 QString dump()
const override;
550 QVariant
value()
const {
return mValue; }
555 QString valueAsString()
const;
576 QString dump()
const override;
583 QString
name()
const {
return mName; }
606 QString dump()
const override;
613 QString
name()
const {
return mName; }
643 QString dump()
const override;
675 std::unique_ptr<QgsEsriArcadeExpression> mContainerExpression;
677 bool mIsSafeAccess =
false;
711 BitwiseSignedRightShift,
712 BitwiseUnsignedRightShift,
716 static const char *BINARY_OPERATOR_TEXT[]
SIP_SKIP;
726 QString dump()
const override;
748 int precedence()
const;
753 bool leftAssociative()
const;
758 QString text()
const;
768 BinaryOperator mBinaryOperator;
769 std::unique_ptr<QgsEsriArcadeExpression> mLeftOperand;
770 std::unique_ptr<QgsEsriArcadeExpression> mRightOperand;
798 static const char *UNARY_OPERATOR_TEXT[]
SIP_SKIP;
808 QString dump()
const override;
825 QString text()
const;
835 UnaryOperator mUnaryOperator;
836 std::unique_ptr<QgsEsriArcadeExpression> mOperand;
860 QString dump()
const override;
872 QList<QgsEsriArcadeExpression *>
arguments()
const {
return mArguments; }
882 QString mFunctionName;
883 QList<QgsEsriArcadeExpression *> mArguments;
905 QString dump()
const override;
927 std::unique_ptr<QgsEsriArcadeExpression> mContainerExpression;
928 std::unique_ptr<QgsEsriArcadeExpression> mIndexExpression;
954 QString dump()
const override;
971 QList<QgsEsriArcadeExpression *> mElements;
997 QString
key()
const {
return mKey; }
1019 QString dump() const;
1030 std::unique_ptr<QgsEsriArcadeExpression> mValue;
1031 bool mIsAutoKey =
false;
1054 QString dump()
const override;
1071 QList<QgsEsriArcadeDictionaryElement *> mElements;
1091 QString dump()
const override;
1118 std::unique_ptr<QgsEsriArcadeExpression> mCondition;
1119 std::unique_ptr<QgsEsriArcadeBlockStatement> mTrueBlock;
1120 std::unique_ptr<QgsEsriArcadeBlockStatement> mFalseBlock;
1142 QString dump()
const override;
1174 std::unique_ptr<QgsEsriArcadeStatement> mInitialization;
1175 std::unique_ptr<QgsEsriArcadeExpression> mCondition;
1176 std::unique_ptr<QgsEsriArcadeNode> mStep;
1177 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
1208 QString dump()
const override;
1245 IterationType mIterationType = IterationType::ForIn;
1246 QString mVariableName;
1247 bool mIsVariableDeclaration =
false;
1248 std::unique_ptr<QgsEsriArcadeExpression> mCollection;
1249 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
1269 QString dump()
const override;
1291 std::unique_ptr<QgsEsriArcadeExpression> mCondition;
1292 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
1310 QString dump()
const override;
1330 QString dump()
const override;
1470 QString
dump()
const;
Represents an array literal expression.
QgsEsriArcadeArrayLiteralExpression(const QList< QgsEsriArcadeExpression * > &elements)
Constructor for QgsEsriArcadeArrayLiteralExpression.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QList< QgsEsriArcadeExpression * > elements() const
Returns the list of element expressions.
Represents a variable reassignment statement.
AssignmentOperator
Assignment operator types.
QgsEsriArcadeExpression * value() const
Returns the assigned value expression.
QgsEsriArcadeAssignmentStatement(AssignmentOperator assignmentOperator, QgsEsriArcadeExpression *target, QgsEsriArcadeExpression *value)
Constructor for QgsEsriArcadeAssignmentStatement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeExpression * target() const
Returns the target expression being assigned to.
AssignmentOperator assignmentOperator() const
Returns the assignment operator.
Represents a binary operation expression.
QgsEsriArcadeBinaryOperatorExpression(BinaryOperator binaryOperator, QgsEsriArcadeExpression *leftOperand, QgsEsriArcadeExpression *rightOperand)
Constructor for QgsEsriArcadeBinaryOperatorExpression.
BinaryOperator binaryOperator() const
Returns the binary operator.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
BinaryOperator
Binary operator enumeration.
QgsEsriArcadeExpression * rightOperand() const
Returns the right-hand operand expression.
QgsEsriArcadeExpression * leftOperand() const
Returns the left-hand operand expression.
Represents a sequence or block of statements enclosed in braces.
int count() const
Returns the number of statements in this block.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeBlockStatement()=default
QList< QgsEsriArcadeStatement * > statements() const
Returns the list of statements contained within this block.
Represents a break loop control statement.
QgsEsriArcadeBreakStatement()=default
Constructor for QgsEsriArcadeBreakStatement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
Represents a continue loop control statement.
QgsEsriArcadeContinueStatement()=default
Constructor for QgsEsriArcadeContinueStatement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
Represents a key-value entry in an Esri Arcade dictionary literal.
~QgsEsriArcadeDictionaryElement()
QString key() const
Returns the entry key.
bool isAutoKey() const
Returns true if the entry was defined using auto-keys.
QgsEsriArcadeExpression * value() const
Returns the entry value expression.
QgsEsriArcadeDictionaryElement(const QString &key, QgsEsriArcadeExpression *value, bool isAutoKey=false)
Constructor for QgsEsriArcadeDictionaryElement.
Represents a dictionary literal expression.
QgsEsriArcadeDictionaryLiteralExpression(const QList< QgsEsriArcadeDictionaryElement * > &elements)
Constructor for QgsEsriArcadeDictionaryLiteralExpression.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QList< QgsEsriArcadeDictionaryElement * > elements() const
Returns the dictionary elements.
Represents an expression evaluated as a statement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeExpressionStatement(QgsEsriArcadeExpression *expression)
Constructor for QgsEsriArcadeExpressionStatement.
QgsEsriArcadeExpression * expression() const
Returns the underlying expression.
Base class for expression nodes in an Esri Arcade script.
~QgsEsriArcadeExpression() override=default
Represents a range based for...in or for...of iteration statement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
IterationType iterationType() const
Returns the iteration type (for...in or for...of).
QgsEsriArcadeForInStatement(IterationType iterationType, const QString &variableName, bool isVariableDeclaration, QgsEsriArcadeExpression *collection, QgsEsriArcadeBlockStatement *body)
Constructor for QgsEsriArcadeForInStatement.
QgsEsriArcadeExpression * collection() const
Returns the collection expression being iterated over.
QgsEsriArcadeBlockStatement * body() const
Returns the loop body block statement.
IterationType
Type of iteration loop.
QString variableName() const
Returns the loop variable identifier name.
bool isVariableDeclaration() const
Returns true if the loop variable was declared with the var keyword.
Represents a standard counter-based for loop.
QgsEsriArcadeNode * step() const
Returns the step expression or statement, or nullptr if none.
QgsEsriArcadeBlockStatement * body() const
Returns the loop body block statement.
QgsEsriArcadeStatement * initialization() const
Returns the initialization statement, or nullptr if none.
QgsEsriArcadeForStatement(QgsEsriArcadeStatement *initialization, QgsEsriArcadeExpression *condition, QgsEsriArcadeNode *step, QgsEsriArcadeBlockStatement *body)
Constructor for QgsEsriArcadeForStatement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeExpression * condition() const
Returns the loop condition expression, or nullptr if none.
Represents a function call expression.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QList< QgsEsriArcadeExpression * > arguments() const
Returns the list of argument expressions.
QString functionName() const
Returns the function name.
QgsEsriArcadeFunctionCallExpression(const QString &functionName, const QList< QgsEsriArcadeExpression * > &arguments)
Constructor for QgsEsriArcadeFunctionCallExpression.
Represents a function declaration statement.
QString functionName() const
Returns the function name.
QStringList parameters() const
Returns the parameter names.
QgsEsriArcadeBlockStatement * body() const
Returns the function body block.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeFunctionDeclarationStatement(const QString &functionName, const QStringList ¶meters, QgsEsriArcadeBlockStatement *body)
Constructor for QgsEsriArcadeFunctionDeclarationStatement.
Represents an if statement.
QgsEsriArcadeExpression * condition() const
Returns the condition expression.
QgsEsriArcadeIfStatement(QgsEsriArcadeExpression *condition, QgsEsriArcadeBlockStatement *trueBlock, QgsEsriArcadeBlockStatement *falseBlock=nullptr)
Constructor for QgsEsriArcadeIfStatement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeBlockStatement * falseBlock() const
Returns the statement block executed when the condition evaluates to false, or nullptr if none.
QgsEsriArcadeBlockStatement * trueBlock() const
Returns the statement block executed when the condition evaluates to true.
Represents an array or dictionary index subscript expression.
QgsEsriArcadeExpression * indexExpression() const
Returns the index expression.
QgsEsriArcadeIndexExpression(QgsEsriArcadeExpression *containerExpression, QgsEsriArcadeExpression *indexExpression)
Constructor for QgsEsriArcadeIndexExpression.
QgsEsriArcadeExpression * containerExpression() const
Returns the container expression being indexed.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
Represents a literal value (number, text string, boolean, or null).
QVariant value() const
Returns the literal value.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeLiteralExpression(const QVariant &value)
Constructor for QgsEsriArcadeLiteralExpression.
Represents a member access expression using dot or bracket notation.
bool isSafeAccess() const
Returns true if member access uses the safe access operator "?.".
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeExpression * containerExpression() const
Returns the container expression being accessed.
QString memberName() const
Returns the member attribute name.
void setIsSafeAccess(bool isSafeAccess)
Sets whether member access uses the safe access operator "?.".
QgsEsriArcadeMemberAccessExpression(QgsEsriArcadeExpression *containerExpression, const QString &memberName, bool isSafeAccess=false)
Constructor for QgsEsriArcadeMemberAccessExpression.
Represents an abstract node for an Esri Arcade script.
virtual void accept(QgsEsriArcadeVisitor &visitor) const =0
Accepts a visitor to traverse the node.
virtual QgsEsriArcadeNode * clone() const =0
Creates a copy of the node.
virtual QgsEsriArcadeNode::NodeType nodeType() const =0
Returns the node type.
virtual QString dump() const =0
Returns the formatted script representation of the node.
NodeType
Node type identifier.
@ BreakStatement
Break statement.
@ ForInStatement
For x in y loop.
@ ContinueStatement
Continue statement.
@ ArrayLiteralExpression
A literal array, where the element values may be expressions themselves (eg [1, 2,...
@ BinaryOperatorExpression
Binary Operator.
@ AssignmentStatement
Variable assignment statement.
@ IndexExpression
Index operator.
@ LiteralExpression
Literal.
@ ProfileVariableReferenceExpression
Reference to a profile variable (eg $feature).
@ IfStatement
If statement.
@ DictionaryLiteralExpression
A literal dictionary, eg {key: 1, other_key: 2}.
@ FunctionCallExpression
Function call.
@ ExpressionStatement
Expression.
@ VariableDeclarationStatement
Variable declaration statement.
@ MemberAccessExpression
Member access via bracket or notation (eg $feature.ATTRIBUTE or $feature["ATTRIBUTE"]).
@ WhileStatement
While loop.
@ VariableReferenceExpression
Reference to a standard variable.
@ ReturnStatement
Return statement.
@ FunctionDeclarationStatement
Function declaration.
@ UnaryOperatorExpression
Operator.
@ BlockStatement
Block statement (a list of statements grouped together in a block).
virtual ~QgsEsriArcadeNode()=default
Represents a reference to a profile variable.
QgsEsriArcadeProfileVariableReferenceExpression(const QString &name)
Constructor for QgsEsriArcadeProfileVariableReferenceExpression.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QString name() const
Returns the profile variable name, including the leading $ symbol.
void visit(const QgsEsriArcadeBlockStatement &node) override
Visit a QgsEsriArcadeBlockStatement node.
QgsEsriArcadeRecursiveVisitor()=default
Represents a return statement.
QgsEsriArcadeReturnStatement(QgsEsriArcadeExpression *expression=nullptr)
Constructor for QgsEsriArcadeReturnStatement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeExpression * expression() const
Returns the expression returned by the statement, or nullptr if void return.
QString dump() const
Dumps the abstract syntax tree back into an Arcade script string.
std::unique_ptr< QgsEsriArcadeBlockStatement > mRootBlock
void acceptVisitor(QgsEsriArcadeVisitor &visitor) const
Accepts a visitor to traverse the script abstract syntax tree.
const QgsEsriArcadeBlockStatement * rootBlock() const
Returns the root block statement node, or nullptr if parsing failed.
QgsEsriArcadeScript & operator=(const QgsEsriArcadeScript &other)
bool hasParserError() const
Returns true if a parsing error occurred.
static QString quotedString(const QString &text)
Returns a properly quoted string literal (enclosed in double quotes with escape sequences).
QgsEsriArcadeScript(const QString &scriptText=QString())
Creates a new script from scriptText.
QString script() const
Returns the original script text.
QString parserErrorString() const
Returns parser error description.
QString mParserErrorString
Base class for statement nodes in an Esri Arcade script.
~QgsEsriArcadeStatement() override=default
Represents a unary operation expression.
QgsEsriArcadeUnaryOperatorExpression(UnaryOperator unaryOperator, QgsEsriArcadeExpression *operand)
Constructor for QgsEsriArcadeUnaryOperatorExpression.
QgsEsriArcadeExpression * operand() const
Returns the operand expression.
UnaryOperator unaryOperator() const
Returns the unary operator.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
UnaryOperator
Unary operator enumeration.
Represents a variable declaration statement.
QgsEsriArcadeVariableDeclarationStatement(const QString &variableName, QgsEsriArcadeExpression *initializer=nullptr)
Constructor for QgsEsriArcadeVariableDeclarationStatement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeExpression * initializer() const
Returns the optional initializer expression, or nullptr if uninitialized.
QString variableName() const
Returns the declared variable name.
Represents a reference to a variable identifier.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QString name() const
Returns the variable identifier name.
QgsEsriArcadeVariableReferenceExpression(const QString &name)
Constructor for QgsEsriArcadeVariableReferenceExpression.
Abstract visitor interface for traversing Esri Arcade abstract syntax trees.
virtual void visit(const QgsEsriArcadeUnaryOperatorExpression &node)=0
Visit a QgsEsriArcadeUnaryOperatorExpression node.
virtual void visit(const QgsEsriArcadeWhileStatement &node)=0
Visit a QgsEsriArcadeWhileStatement node.
virtual void visit(const QgsEsriArcadeProfileVariableReferenceExpression &node)=0
Visit a QgsEsriArcadeProfileVariableReferenceExpression node.
virtual void visit(const QgsEsriArcadeVariableReferenceExpression &node)=0
Visit a QgsEsriArcadeVariableReferenceExpression node.
virtual void visit(const QgsEsriArcadeFunctionDeclarationStatement &node)=0
Visit a QgsEsriArcadeFunctionDeclarationStatement node.
virtual void visit(const QgsEsriArcadeArrayLiteralExpression &node)=0
Visit a QgsEsriArcadeArrayLiteralExpression node.
virtual void visit(const QgsEsriArcadeMemberAccessExpression &node)=0
Visit a QgsEsriArcadeMemberAccessExpression node.
virtual void visit(const QgsEsriArcadeExpressionStatement &node)=0
Visit a QgsEsriArcadeExpressionStatement node.
virtual void visit(const QgsEsriArcadeForStatement &node)=0
Visit a QgsEsriArcadeForStatement node.
virtual void visit(const QgsEsriArcadeReturnStatement &node)=0
Visit a QgsEsriArcadeReturnStatement node.
virtual void visit(const QgsEsriArcadeBinaryOperatorExpression &node)=0
Visit a QgsEsriArcadeBinaryOperatorExpression node.
virtual void visit(const QgsEsriArcadeIfStatement &node)=0
Visit a QgsEsriArcadeIfStatement node.
virtual void visit(const QgsEsriArcadeBlockStatement &node)=0
Visit a QgsEsriArcadeBlockStatement node.
virtual void visit(const QgsEsriArcadeBreakStatement &node)=0
Visit a QgsEsriArcadeBreakStatement node.
virtual void visit(const QgsEsriArcadeIndexExpression &node)=0
Visit a QgsEsriArcadeIndexExpression node.
virtual void visit(const QgsEsriArcadeContinueStatement &node)=0
Visit a QgsEsriArcadeContinueStatement node.
virtual void visit(const QgsEsriArcadeForInStatement &node)=0
Visit a QgsEsriArcadeForInStatement node.
virtual void visit(const QgsEsriArcadeVariableDeclarationStatement &node)=0
Visit a QgsEsriArcadeVariableDeclarationStatement node.
virtual void visit(const QgsEsriArcadeLiteralExpression &node)=0
Visit a QgsEsriArcadeLiteralExpression node.
virtual void visit(const QgsEsriArcadeAssignmentStatement &node)=0
Visit a QgsEsriArcadeAssignmentStatement node.
virtual void visit(const QgsEsriArcadeFunctionCallExpression &node)=0
Visit a QgsEsriArcadeFunctionCallExpression node.
virtual ~QgsEsriArcadeVisitor()=default
virtual void visit(const QgsEsriArcadeDictionaryLiteralExpression &node)=0
Visit a QgsEsriArcadeDictionaryLiteralExpression node.
Represents a while loop statement.
QgsEsriArcadeBlockStatement * body() const
Returns the loop body block statement.
QgsEsriArcadeNode::NodeType nodeType() const override
Returns the node type.
QgsEsriArcadeWhileStatement(QgsEsriArcadeExpression *condition, QgsEsriArcadeBlockStatement *body)
Constructor for QgsEsriArcadeWhileStatement.
QgsEsriArcadeExpression * condition() const
Returns the loop condition expression.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)