24#include <QCoreApplication>
31using namespace Qt::StringLiterals;
61 switch ( sipCpp->nodeType() )
64 sipType = sipType_QgsVbScriptBlockStatement;
67 sipType = sipType_QgsVbScriptVariableDeclarationStatement;
70 sipType = sipType_QgsVbScriptAssignmentStatement;
73 sipType = sipType_QgsVbScriptIfStatement;
76 sipType = sipType_QgsVbScriptForStatement;
79 sipType = sipType_QgsVbScriptForEachStatement;
82 sipType = sipType_QgsVbScriptWhileStatement;
85 sipType = sipType_QgsVbScriptExitStatement;
88 sipType = sipType_QgsVbScriptFunctionDeclarationStatement;
91 sipType = sipType_QgsVbScriptExpressionStatement;
94 sipType = sipType_QgsVbScriptLiteralExpression;
97 sipType = sipType_QgsVbScriptVariableReferenceExpression;
100 sipType = sipType_QgsVbScriptMemberAccessExpression;
103 sipType = sipType_QgsVbScriptBinaryOperatorExpression;
106 sipType = sipType_QgsVbScriptUnaryOperatorExpression;
109 sipType = sipType_QgsVbScriptFunctionCallExpression;
112 sipType = sipType_QgsVbScriptArrayLiteralExpression;
115 sipType = sipType_QgsVbScriptFieldReferenceExpression;
131 VariableDeclarationStatement,
133 FunctionDeclarationStatement,
136 VariableReferenceExpression,
137 MemberAccessExpression,
138 BinaryOperatorExpression,
139 UnaryOperatorExpression,
140 FunctionCallExpression,
142 ArrayLiteralExpression,
148 FieldReferenceExpression,
163 virtual QString
dump()
const = 0;
232 QString dump()
const override;
251 int count()
const {
return mStatements.count(); }
261 QList<QgsVbScriptStatement *> mStatements;
286 QString dump()
const override;
303 QStringList mVariableNames;
325 QString dump()
const override;
342 bool isSet()
const {
return mIsSet; }
352 std::unique_ptr<QgsVbScriptExpression> mTarget;
353 std::unique_ptr<QgsVbScriptExpression> mValue;
376 QString dump()
const override;
398 bool isSub()
const {
return mIsSub; }
408 QString mFunctionName;
409 QStringList mParameters;
410 std::unique_ptr<QgsVbScriptBlockStatement> mBody;
433 QString dump()
const override;
450 std::unique_ptr<QgsVbScriptExpression> mExpression;
468 QString dump()
const override;
475 QVariant
value()
const {
return mValue; }
480 QString valueAsString()
const;
501 QString dump()
const override;
508 QString
name()
const {
return mName; }
531 QString dump()
const override;
553 std::unique_ptr<QgsVbScriptExpression> mContainerExpression;
594 static const char *BINARY_OPERATOR_TEXT[]
SIP_SKIP;
604 QString dump()
const override;
626 int precedence()
const;
631 bool leftAssociative()
const;
636 QString text()
const;
646 BinaryOperator mBinaryOperator;
647 std::unique_ptr<QgsVbScriptExpression> mLeftOperand;
648 std::unique_ptr<QgsVbScriptExpression> mRightOperand;
671 static const char *UNARY_OPERATOR_TEXT[]
SIP_SKIP;
681 QString dump()
const override;
698 QString text()
const;
708 UnaryOperator mUnaryOperator;
709 std::unique_ptr<QgsVbScriptExpression> mOperand;
733 QString dump()
const override;
745 QList<QgsVbScriptExpression *>
arguments()
const {
return mArguments; }
755 std::unique_ptr<QgsVbScriptExpression> mTargetExpression;
756 QList<QgsVbScriptExpression *> mArguments;
778 QString dump()
const override;
800 std::unique_ptr<QgsVbScriptExpression> mContainerExpression;
801 std::unique_ptr<QgsVbScriptExpression> mIndexExpression;
825 QString dump()
const override;
842 QList<QgsVbScriptExpression *> mElements;
864 QString dump()
const override;
896 std::unique_ptr<QgsVbScriptExpression> mCondition;
897 std::unique_ptr<QgsVbScriptBlockStatement> mTrueBlock;
898 std::unique_ptr<QgsVbScriptBlockStatement> mFalseBlock;
899 bool mIsInline =
false;
925 QString dump()
const override;
962 QString mVariableName;
963 std::unique_ptr<QgsVbScriptExpression> mStartExpression;
964 std::unique_ptr<QgsVbScriptExpression> mEndExpression;
965 std::unique_ptr<QgsVbScriptExpression> mStepExpression;
966 std::unique_ptr<QgsVbScriptBlockStatement> mBody;
986 QString dump()
const override;
1013 QString mVariableName;
1014 std::unique_ptr<QgsVbScriptExpression> mCollection;
1015 std::unique_ptr<QgsVbScriptBlockStatement> mBody;
1047 QString dump()
const override;
1073 LoopType mLoopType = LoopType::WhileWend;
1074 std::unique_ptr<QgsVbScriptExpression> mCondition;
1075 std::unique_ptr<QgsVbScriptBlockStatement> mBody;
1105 QString dump()
const override;
1115 ExitType mExitType = ExitType::ExitFunction;
1135 QString dump()
const override;
1251 explicit QgsVbScript(
const QString &scriptText = QString() );
1281 QString
dump()
const;
Represents an array literal expression.
QgsVbScriptArrayLiteralExpression(const QList< QgsVbScriptExpression * > &elements)
Constructor for QgsVbScriptArrayLiteralExpression.
QList< QgsVbScriptExpression * > elements() const
Returns the list of element expressions.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
Represents a variable reassignment statement.
bool isSet() const
Returns true if the assignment uses the Set keyword.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptExpression * target() const
Returns the target expression being assigned to.
QgsVbScriptAssignmentStatement(QgsVbScriptExpression *target, QgsVbScriptExpression *value, bool isSet=false)
Constructor for QgsVbScriptAssignmentStatement.
QgsVbScriptExpression * value() const
Returns the assigned value expression.
Represents a binary operation expression.
QgsVbScriptBinaryOperatorExpression(BinaryOperator binaryOperator, QgsVbScriptExpression *leftOperand, QgsVbScriptExpression *rightOperand)
Constructor for QgsVbScriptBinaryOperatorExpression.
BinaryOperator
Binary operator enumeration.
QgsVbScriptExpression * leftOperand() const
Returns the left-hand operand expression.
BinaryOperator binaryOperator() const
Returns the binary operator.
QgsVbScriptExpression * rightOperand() const
Returns the right-hand operand expression.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
Represents a sequence of statements.
QList< QgsVbScriptStatement * > statements() const
Returns the list of statements contained within this block.
QgsVbScriptBlockStatement()=default
int count() const
Returns the number of statements in this block.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
Represents an Exit loop or Exit Sub/Function statement.
QgsVbScriptExitStatement(ExitType exitType)
Constructor for QgsVbScriptExitStatement.
ExitType exitType() const
Returns the exit target scope.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
ExitType
Object to exit from.
Represents an expression evaluated as a statement.
QgsVbScriptExpressionStatement(QgsVbScriptExpression *expression)
Constructor for QgsVbScriptExpressionStatement.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptExpression * expression() const
Returns the underlying expression.
Base class for expression nodes in a VBScript script.
~QgsVbScriptExpression() override=default
Represents an ESRI specific node for a reference to an attribute field enclosed in square brackets.
QgsVbScriptFieldReferenceExpression(const QString &fieldName)
Constructor for QgsVbScriptFieldReferenceExpression.
QString fieldName() const
Returns the unescaped field name.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
Represents a for ... each loop.
QString variableName() const
Returns the loop variable identifier name.
QgsVbScriptBlockStatement * body() const
Returns the loop body block statement.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptForEachStatement(const QString &variableName, QgsVbScriptExpression *collection, QgsVbScriptBlockStatement *body)
Constructor for QgsVbScriptForEachStatement.
QgsVbScriptExpression * collection() const
Returns the collection expression being iterated over.
Represents a standard counter-based for loop.
QgsVbScriptExpression * startExpression() const
Returns the initial counter expression.
QgsVbScriptExpression * stepExpression() const
Returns the step increment expression, or nullptr if default.
QgsVbScriptBlockStatement * body() const
Returns the loop body block statement.
QgsVbScriptForStatement(const QString &variableName, QgsVbScriptExpression *startExpression, QgsVbScriptExpression *endExpression, QgsVbScriptExpression *stepExpression, QgsVbScriptBlockStatement *body)
Constructor for QgsVbScriptForStatement.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptExpression * endExpression() const
Returns the terminal counter expression.
QString variableName() const
Returns the loop variable identifier name.
Represents a function call expression.
QgsVbScriptFunctionCallExpression(QgsVbScriptExpression *targetExpression, const QList< QgsVbScriptExpression * > &arguments)
Constructor for QgsVbScriptFunctionCallExpression.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QList< QgsVbScriptExpression * > arguments() const
Returns the list of argument expressions.
QgsVbScriptExpression * targetExpression() const
Returns the callee expression.
Represents a function declaration statement.
QStringList parameters() const
Returns the parameter names.
QgsVbScriptBlockStatement * body() const
Returns the function body block.
QString functionName() const
Returns the function name.
QgsVbScriptFunctionDeclarationStatement(const QString &functionName, const QStringList ¶meters, QgsVbScriptBlockStatement *body, bool isSub=false)
Constructor for QgsVbScriptFunctionDeclarationStatement.
bool isSub() const
Returns true if this is a Sub procedure rather than a Function.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
Represents an if statement.
QgsVbScriptBlockStatement * falseBlock() const
Returns the statement block executed when the condition evaluates to false, or nullptr if none.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptIfStatement(QgsVbScriptExpression *condition, QgsVbScriptBlockStatement *trueBlock, QgsVbScriptBlockStatement *falseBlock=nullptr, bool isInline=false)
Constructor for QgsVbScriptIfStatement.
QgsVbScriptExpression * condition() const
Returns the condition expression.
bool isInline() const
Returns true if this statement was declared as a single-line inline If.
QgsVbScriptBlockStatement * trueBlock() const
Returns the statement block executed when the condition evaluates to true.
Represents an array or dictionary index subscript expression.
QgsVbScriptIndexExpression(QgsVbScriptExpression *containerExpression, QgsVbScriptExpression *indexExpression)
Constructor for QgsVbScriptIndexExpression.
QgsVbScriptExpression * indexExpression() const
Returns the index expression.
QgsVbScriptExpression * containerExpression() const
Returns the container expression being indexed.
QgsVbScriptNode::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.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptLiteralExpression(const QVariant &value)
Constructor for QgsVbScriptLiteralExpression.
Represents a member access expression using bracket notation.
QgsVbScriptExpression * containerExpression() const
Returns the container expression being accessed.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptMemberAccessExpression(QgsVbScriptExpression *containerExpression, const QString &memberName)
Constructor for QgsVbScriptMemberAccessExpression.
QString memberName() const
Returns the member attribute name.
Represents an abstract node for a VBScript script.
NodeType
Node type identifier.
@ ArrayLiteralExpression
A literal array, where the element values may be expressions themselves (eg [1, 2,...
@ ExitStatement
Exit loop statement.
@ BinaryOperatorExpression
Binary Operator.
@ AssignmentStatement
Variable assignment statement.
@ IndexExpression
Index operator.
@ LiteralExpression
Literal.
@ IfStatement
If statement.
@ 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.
@ ForEachStatement
For each loop.
@ FieldReferenceExpression
Special ESRI specific reference to a layer's field (eg [FIELD_NAME]).
@ FunctionDeclarationStatement
Function declaration.
@ UnaryOperatorExpression
Operator.
@ BlockStatement
Block statement (a list of statements grouped together in a block).
virtual void accept(QgsVbScriptVisitor &visitor) const =0
Accepts a visitor to traverse the node.
virtual QString dump() const =0
Returns the formatted script representation of the node.
virtual QgsVbScriptNode::NodeType nodeType() const =0
Returns the node type.
virtual QgsVbScriptNode * clone() const =0
Creates a copy of the node.
virtual ~QgsVbScriptNode()=default
void visit(const QgsVbScriptBlockStatement &node) override
Visit a QgsVbScriptBlockStatement node.
QgsVbScriptRecursiveVisitor()=default
Base class for statement nodes in a VBScript script.
~QgsVbScriptStatement() override=default
Represents a unary operation expression.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptUnaryOperatorExpression(UnaryOperator unaryOperator, QgsVbScriptExpression *operand)
Constructor for QgsVbScriptUnaryOperatorExpression.
UnaryOperator
Unary operator enumeration.
QgsVbScriptExpression * operand() const
Returns the operand expression.
UnaryOperator unaryOperator() const
Returns the unary operator.
Represents a variable declaration statement.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QStringList variableNames() const
Returns the declared variable names.
QgsVbScriptVariableDeclarationStatement(const QString &variableName)
Constructor for QgsVbScriptVariableDeclarationStatement.
Represents a reference to a variable identifier.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QString name() const
Returns the variable identifier name.
QgsVbScriptVariableReferenceExpression(const QString &name)
Constructor for QgsVbScriptVariableReferenceExpression.
Abstract visitor interface for traversing VBScript abstract syntax trees.
virtual void visit(const QgsVbScriptLiteralExpression &node)=0
Visit a QgsVbScriptLiteralExpression node.
virtual void visit(const QgsVbScriptArrayLiteralExpression &node)=0
Visit a QgsVbScriptArrayLiteralExpression node.
virtual void visit(const QgsVbScriptWhileStatement &node)=0
Visit a QgsVbScriptWhileStatement node.
virtual void visit(const QgsVbScriptFunctionDeclarationStatement &node)=0
Visit a QgsVbScriptFunctionDeclarationStatement node.
virtual void visit(const QgsVbScriptBinaryOperatorExpression &node)=0
Visit a QgsVbScriptBinaryOperatorExpression node.
virtual void visit(const QgsVbScriptUnaryOperatorExpression &node)=0
Visit a QgsVbScriptUnaryOperatorExpression node.
virtual void visit(const QgsVbScriptExitStatement &node)=0
Visit a QgsVbScriptExitStatement node.
virtual void visit(const QgsVbScriptVariableDeclarationStatement &node)=0
Visit a QgsVbScriptVariableDeclarationStatement node.
virtual void visit(const QgsVbScriptBlockStatement &node)=0
Visit a QgsVbScriptBlockStatement node.
virtual void visit(const QgsVbScriptExpressionStatement &node)=0
Visit a QgsVbScriptExpressionStatement node.
virtual void visit(const QgsVbScriptVariableReferenceExpression &node)=0
Visit a QgsVbScriptVariableReferenceExpression node.
virtual void visit(const QgsVbScriptAssignmentStatement &node)=0
Visit a QgsVbScriptAssignmentStatement node.
virtual void visit(const QgsVbScriptIndexExpression &node)=0
Visit a QgsVbScriptIndexExpression node.
virtual void visit(const QgsVbScriptFieldReferenceExpression &node)=0
Visit a QgsVbScriptFieldReferenceExpression node.
virtual void visit(const QgsVbScriptFunctionCallExpression &node)=0
Visit a QgsVbScriptFunctionCallExpression node.
virtual void visit(const QgsVbScriptForStatement &node)=0
Visit a QgsVbScriptForStatement node.
virtual void visit(const QgsVbScriptForEachStatement &node)=0
Visit a QgsVbScriptForEachStatement node.
virtual void visit(const QgsVbScriptIfStatement &node)=0
Visit a QgsVbScriptIfStatement node.
virtual void visit(const QgsVbScriptMemberAccessExpression &node)=0
Visit a QgsVbScriptMemberAccessExpression node.
virtual ~QgsVbScriptVisitor()=default
Represents a while loop statement.
LoopType loopType() const
Returns the loop variant type.
LoopType
Type of while or do loop.
QgsVbScriptExpression * condition() const
Returns the loop condition expression.
QgsVbScriptNode::NodeType nodeType() const override
Returns the node type.
QgsVbScriptBlockStatement * body() const
Returns the loop body block statement.
QgsVbScriptWhileStatement(LoopType loopType, QgsVbScriptExpression *condition, QgsVbScriptBlockStatement *body)
Constructor for QgsVbScriptWhileStatement.
static QString extractFieldReference(const QString &text)
Strips enclosing square brackets from text and unescapes double right brackets.
QgsVbScript & operator=(const QgsVbScript &other)
QString script() const
Returns the original script text.
std::unique_ptr< QgsVbScriptBlockStatement > mRootBlock
void acceptVisitor(QgsVbScriptVisitor &visitor) const
Accepts a visitor to traverse the script abstract syntax tree.
static QString quotedFieldReference(const QString &fieldName)
Returns a field name enclosed in square brackets with internal right brackets escaped.
QString parserErrorString() const
Returns parser error description.
const QgsVbScriptBlockStatement * rootBlock() const
Returns the root block statement node, or nullptr if parsing failed.
QString mParserErrorString
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).
QString dump() const
Dumps the abstract syntax tree back into an Arcade script string.
QgsVbScript(const QString &scriptText=QString())
Creates a new script from scriptText.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)