QGIS API Documentation 4.3.0-Master (0cef2469b72)
Loading...
Searching...
No Matches
qgsvbscript.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvbscript.h
3 --------------------
4 begin : November 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSVBSCRIPT_H
17#define QGSVBSCRIPT_H
18
19#include <memory>
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23
24#include <QCoreApplication>
25#include <QList>
26#include <QMetaType>
27#include <QString>
28#include <QStringList>
29#include <QVariant>
30
31using namespace Qt::StringLiterals;
32
44
57class CORE_EXPORT QgsVbScriptNode
58{
59#ifdef SIP_RUN
61 switch ( sipCpp->nodeType() )
62 {
64 sipType = sipType_QgsVbScriptBlockStatement;
65 break;
67 sipType = sipType_QgsVbScriptVariableDeclarationStatement;
68 break;
70 sipType = sipType_QgsVbScriptAssignmentStatement;
71 break;
73 sipType = sipType_QgsVbScriptIfStatement;
74 break;
76 sipType = sipType_QgsVbScriptForStatement;
77 break;
79 sipType = sipType_QgsVbScriptForEachStatement;
80 break;
82 sipType = sipType_QgsVbScriptWhileStatement;
83 break;
85 sipType = sipType_QgsVbScriptExitStatement;
86 break;
88 sipType = sipType_QgsVbScriptFunctionDeclarationStatement;
89 break;
91 sipType = sipType_QgsVbScriptExpressionStatement;
92 break;
94 sipType = sipType_QgsVbScriptLiteralExpression;
95 break;
97 sipType = sipType_QgsVbScriptVariableReferenceExpression;
98 break;
100 sipType = sipType_QgsVbScriptMemberAccessExpression;
101 break;
103 sipType = sipType_QgsVbScriptBinaryOperatorExpression;
104 break;
106 sipType = sipType_QgsVbScriptUnaryOperatorExpression;
107 break;
109 sipType = sipType_QgsVbScriptFunctionCallExpression;
110 break;
112 sipType = sipType_QgsVbScriptArrayLiteralExpression;
113 break;
115 sipType = sipType_QgsVbScriptFieldReferenceExpression;
116 break;
117 default:
118 sipType = nullptr;
119 break;
120 }
121 SIP_END
122#endif
123
124 public:
128 enum class NodeType
129 {
130 BlockStatement,
131 VariableDeclarationStatement,
132 AssignmentStatement,
133 FunctionDeclarationStatement,
134 ExpressionStatement,
135 LiteralExpression,
136 VariableReferenceExpression,
137 MemberAccessExpression,
138 BinaryOperatorExpression,
139 UnaryOperatorExpression,
140 FunctionCallExpression,
141 IndexExpression,
142 ArrayLiteralExpression,
143 IfStatement,
144 ForStatement,
145 ForEachStatement,
146 WhileStatement,
147 ExitStatement,
148 FieldReferenceExpression,
149 };
150
151 virtual ~QgsVbScriptNode() = default;
152
157
163 virtual QString dump() const = 0;
164
170 virtual QgsVbScriptNode *clone() const = 0 SIP_FACTORY;
171
175 virtual void accept( QgsVbScriptVisitor &visitor ) const = 0;
176};
177
187class CORE_EXPORT QgsVbScriptStatement : public QgsVbScriptNode
188{
189 public:
190 ~QgsVbScriptStatement() override = default;
191};
192
205class CORE_EXPORT QgsVbScriptExpression : public QgsVbScriptNode
206{
207 public:
208 ~QgsVbScriptExpression() override = default;
209};
210
218{
219 public:
221
227 explicit QgsVbScriptBlockStatement( const QList<QgsVbScriptStatement *> &statements SIP_TRANSFER );
228
230
232 QString dump() const override;
233 QgsVbScriptNode *clone() const override SIP_FACTORY;
234 void accept( QgsVbScriptVisitor &visitor ) const override;
235
241 void appendStatement( QgsVbScriptStatement *statement SIP_TRANSFER );
242
246 QList<QgsVbScriptStatement *> statements() const { return mStatements; }
247
251 int count() const { return mStatements.count(); }
252
253 private:
255 QgsVbScriptBlockStatement &operator=( const QgsVbScriptBlockStatement &other ) = delete;
256
257#ifdef SIP_RUN
259#endif
260
261 QList<QgsVbScriptStatement *> mStatements;
262};
263
273{
274 public:
278 explicit QgsVbScriptVariableDeclarationStatement( const QString &variableName );
279
283 explicit QgsVbScriptVariableDeclarationStatement( const QStringList &variableNames );
284
286 QString dump() const override;
287 QgsVbScriptNode *clone() const override SIP_FACTORY;
288 void accept( QgsVbScriptVisitor &visitor ) const override;
289
293 QStringList variableNames() const { return mVariableNames; }
294
295 private:
298
299#ifdef SIP_RUN
301#endif
302
303 QStringList mVariableNames;
304};
305
315{
316 public:
323
325 QString dump() const override;
326 QgsVbScriptNode *clone() const override SIP_FACTORY;
327 void accept( QgsVbScriptVisitor &visitor ) const override;
328
332 QgsVbScriptExpression *target() const { return mTarget.get(); }
333
337 QgsVbScriptExpression *value() const { return mValue.get(); }
338
342 bool isSet() const { return mIsSet; }
343
344 private:
346 QgsVbScriptAssignmentStatement &operator=( const QgsVbScriptAssignmentStatement &other ) = delete;
347
348#ifdef SIP_RUN
350#endif
351
352 std::unique_ptr<QgsVbScriptExpression> mTarget;
353 std::unique_ptr<QgsVbScriptExpression> mValue;
354 bool mIsSet = false;
355};
356
366{
367 public:
374
376 QString dump() const override;
377 QgsVbScriptNode *clone() const override SIP_FACTORY;
378 void accept( QgsVbScriptVisitor &visitor ) const override;
379
383 QString functionName() const { return mFunctionName; }
384
388 QStringList parameters() const { return mParameters; }
389
393 QgsVbScriptBlockStatement *body() const { return mBody.get(); }
394
398 bool isSub() const { return mIsSub; }
399
400 private:
403
404#ifdef SIP_RUN
406#endif
407
408 QString mFunctionName;
409 QStringList mParameters;
410 std::unique_ptr<QgsVbScriptBlockStatement> mBody;
411 bool mIsSub = false;
412};
413
423{
424 public:
431
433 QString dump() const override;
434 QgsVbScriptNode *clone() const override SIP_FACTORY;
435 void accept( QgsVbScriptVisitor &visitor ) const override;
436
440 QgsVbScriptExpression *expression() const { return mExpression.get(); }
441
442 private:
444 QgsVbScriptExpressionStatement &operator=( const QgsVbScriptExpressionStatement &other ) = delete;
445
446#ifdef SIP_RUN
448#endif
449
450 std::unique_ptr<QgsVbScriptExpression> mExpression;
451};
452
460{
461 public:
465 explicit QgsVbScriptLiteralExpression( const QVariant &value );
466
468 QString dump() const override;
469 QgsVbScriptNode *clone() const override SIP_FACTORY;
470 void accept( QgsVbScriptVisitor &visitor ) const override;
471
475 QVariant value() const { return mValue; }
476
480 QString valueAsString() const;
481
482 private:
483 QVariant mValue;
484};
485
493{
494 public:
498 explicit QgsVbScriptVariableReferenceExpression( const QString &name );
499
501 QString dump() const override;
502 QgsVbScriptNode *clone() const override SIP_FACTORY;
503 void accept( QgsVbScriptVisitor &visitor ) const override;
504
508 QString name() const { return mName; }
509
510 private:
511 QString mName;
512};
513
521{
522 public:
529
531 QString dump() const override;
532 QgsVbScriptNode *clone() const override SIP_FACTORY;
533 void accept( QgsVbScriptVisitor &visitor ) const override;
534
538 QgsVbScriptExpression *containerExpression() const { return mContainerExpression.get(); }
539
543 QString memberName() const { return mMemberName; }
544
545 private:
548
549#ifdef SIP_RUN
551#endif
552
553 std::unique_ptr<QgsVbScriptExpression> mContainerExpression;
554 QString mMemberName;
555};
556
564{
565 public:
569 enum class BinaryOperator
570 {
571 Plus,
572 Minus,
573 Multiply,
574 Divide,
575 IntegerDivide,
576 Modulo,
577 Exponent,
578 Concat,
579 Equal,
580 NotEqual,
581 LessThan,
582 GreaterThan,
583 LessThanOrEqual,
584 GreaterThanOrEqual,
585 Is,
586 LogicalAnd,
587 LogicalOr,
588 LogicalXor,
589 LogicalImp,
590 LogicalEqv,
591 };
592
594 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
595
601 QgsVbScriptBinaryOperatorExpression( BinaryOperator binaryOperator, QgsVbScriptExpression *leftOperand SIP_TRANSFER, QgsVbScriptExpression *rightOperand SIP_TRANSFER );
602
604 QString dump() const override;
605 QgsVbScriptNode *clone() const override SIP_FACTORY;
606 void accept( QgsVbScriptVisitor &visitor ) const override;
607
611 BinaryOperator binaryOperator() const { return mBinaryOperator; }
612
616 QgsVbScriptExpression *leftOperand() const { return mLeftOperand.get(); }
617
621 QgsVbScriptExpression *rightOperand() const { return mRightOperand.get(); }
622
626 int precedence() const;
627
631 bool leftAssociative() const;
632
636 QString text() const;
637
638 private:
641
642#ifdef SIP_RUN
644#endif
645
646 BinaryOperator mBinaryOperator;
647 std::unique_ptr<QgsVbScriptExpression> mLeftOperand;
648 std::unique_ptr<QgsVbScriptExpression> mRightOperand;
649};
650
658{
659 public:
663 enum class UnaryOperator
664 {
665 Not,
666 Minus,
667 Plus,
668 };
669
671 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
672
678 QgsVbScriptUnaryOperatorExpression( UnaryOperator unaryOperator, QgsVbScriptExpression *operand SIP_TRANSFER );
679
681 QString dump() const override;
682 QgsVbScriptNode *clone() const override SIP_FACTORY;
683 void accept( QgsVbScriptVisitor &visitor ) const override;
684
688 UnaryOperator unaryOperator() const { return mUnaryOperator; }
689
693 QgsVbScriptExpression *operand() const { return mOperand.get(); }
694
698 QString text() const;
699
700 private:
703
704#ifdef SIP_RUN
706#endif
707
708 UnaryOperator mUnaryOperator;
709 std::unique_ptr<QgsVbScriptExpression> mOperand;
710};
711
721{
722 public:
729
731
733 QString dump() const override;
734 QgsVbScriptNode *clone() const override SIP_FACTORY;
735 void accept( QgsVbScriptVisitor &visitor ) const override;
736
740 QgsVbScriptExpression *targetExpression() const { return mTargetExpression.get(); }
741
745 QList<QgsVbScriptExpression *> arguments() const { return mArguments; }
746
747 private:
750
751#ifdef SIP_RUN
753#endif
754
755 std::unique_ptr<QgsVbScriptExpression> mTargetExpression;
756 QList<QgsVbScriptExpression *> mArguments;
757};
758
768{
769 public:
776
778 QString dump() const override;
779 QgsVbScriptNode *clone() const override SIP_FACTORY;
780 void accept( QgsVbScriptVisitor &visitor ) const override;
781
785 QgsVbScriptExpression *containerExpression() const { return mContainerExpression.get(); }
786
790 QgsVbScriptExpression *indexExpression() const { return mIndexExpression.get(); }
791
792 private:
794 QgsVbScriptIndexExpression &operator=( const QgsVbScriptIndexExpression &other ) = delete;
795
796#ifdef SIP_RUN
798#endif
799
800 std::unique_ptr<QgsVbScriptExpression> mContainerExpression;
801 std::unique_ptr<QgsVbScriptExpression> mIndexExpression;
802};
803
813{
814 public:
820 explicit QgsVbScriptArrayLiteralExpression( const QList<QgsVbScriptExpression *> &elements SIP_TRANSFER );
821
823
825 QString dump() const override;
826 QgsVbScriptNode *clone() const override SIP_FACTORY;
827 void accept( QgsVbScriptVisitor &visitor ) const override;
828
832 QList<QgsVbScriptExpression *> elements() const { return mElements; }
833
834 private:
837
838#ifdef SIP_RUN
840#endif
841
842 QList<QgsVbScriptExpression *> mElements;
843};
844
852{
853 public:
861 );
862
864 QString dump() const override;
865 QgsVbScriptNode *clone() const override SIP_FACTORY;
866 void accept( QgsVbScriptVisitor &visitor ) const override;
867
871 QgsVbScriptExpression *condition() const { return mCondition.get(); }
872
876 QgsVbScriptBlockStatement *trueBlock() const { return mTrueBlock.get(); }
877
881 QgsVbScriptBlockStatement *falseBlock() const { return mFalseBlock.get(); }
882
886 bool isInline() const { return mIsInline; }
887
888 private:
889 QgsVbScriptIfStatement( const QgsVbScriptIfStatement &other ) = delete;
890 QgsVbScriptIfStatement &operator=( const QgsVbScriptIfStatement &other ) = delete;
891
892#ifdef SIP_RUN
894#endif
895
896 std::unique_ptr<QgsVbScriptExpression> mCondition;
897 std::unique_ptr<QgsVbScriptBlockStatement> mTrueBlock;
898 std::unique_ptr<QgsVbScriptBlockStatement> mFalseBlock;
899 bool mIsInline = false;
900};
901
909{
910 public:
917 const QString &variableName,
922 );
923
925 QString dump() const override;
926 QgsVbScriptNode *clone() const override SIP_FACTORY;
927 void accept( QgsVbScriptVisitor &visitor ) const override;
928
932 QString variableName() const { return mVariableName; }
933
937 QgsVbScriptExpression *startExpression() const { return mStartExpression.get(); }
938
942 QgsVbScriptExpression *endExpression() const { return mEndExpression.get(); }
943
947 QgsVbScriptExpression *stepExpression() const { return mStepExpression.get(); }
948
952 QgsVbScriptBlockStatement *body() const { return mBody.get(); }
953
954 private:
955 QgsVbScriptForStatement( const QgsVbScriptForStatement &other ) = delete;
956 QgsVbScriptForStatement &operator=( const QgsVbScriptForStatement &other ) = delete;
957
958#ifdef SIP_RUN
960#endif
961
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;
967};
968
976{
977 public:
984
986 QString dump() const override;
987 QgsVbScriptNode *clone() const override SIP_FACTORY;
988 void accept( QgsVbScriptVisitor &visitor ) const override;
989
993 QString variableName() const { return mVariableName; }
994
998 QgsVbScriptExpression *collection() const { return mCollection.get(); }
999
1003 QgsVbScriptBlockStatement *body() const { return mBody.get(); }
1004
1005 private:
1007 QgsVbScriptForEachStatement &operator=( const QgsVbScriptForEachStatement &other ) = delete;
1008
1009#ifdef SIP_RUN
1011#endif
1012
1013 QString mVariableName;
1014 std::unique_ptr<QgsVbScriptExpression> mCollection;
1015 std::unique_ptr<QgsVbScriptBlockStatement> mBody;
1016};
1017
1025{
1026 public:
1030 enum class LoopType
1031 {
1032 WhileWend,
1033 DoWhile,
1034 DoUntil,
1035 DoLoopWhile,
1036 DoLoopUntil,
1037 };
1038
1045
1047 QString dump() const override;
1048 QgsVbScriptNode *clone() const override SIP_FACTORY;
1049 void accept( QgsVbScriptVisitor &visitor ) const override;
1050
1054 LoopType loopType() const { return mLoopType; }
1055
1059 QgsVbScriptExpression *condition() const { return mCondition.get(); }
1060
1064 QgsVbScriptBlockStatement *body() const { return mBody.get(); }
1065
1066 private:
1068 QgsVbScriptWhileStatement &operator=( const QgsVbScriptWhileStatement &other ) = delete;
1069
1070#ifdef SIP_RUN
1072#endif
1073 LoopType mLoopType = LoopType::WhileWend;
1074 std::unique_ptr<QgsVbScriptExpression> mCondition;
1075 std::unique_ptr<QgsVbScriptBlockStatement> mBody;
1076};
1077
1078
1086{
1087 public:
1091 enum class ExitType
1092 {
1093 ExitDo,
1094 ExitFor,
1095 ExitFunction,
1096 ExitSub,
1097 };
1098
1102 explicit QgsVbScriptExitStatement( ExitType exitType );
1103
1105 QString dump() const override;
1106 QgsVbScriptNode *clone() const override SIP_FACTORY;
1107 void accept( QgsVbScriptVisitor &visitor ) const override;
1108
1112 ExitType exitType() const { return mExitType; }
1113
1114 private:
1115 ExitType mExitType = ExitType::ExitFunction;
1116};
1117
1127{
1128 public:
1132 explicit QgsVbScriptFieldReferenceExpression( const QString &fieldName );
1133
1135 QString dump() const override;
1136 QgsVbScriptNode *clone() const override SIP_FACTORY;
1137 void accept( QgsVbScriptVisitor &visitor ) const override;
1138
1142 QString fieldName() const { return mFieldName; }
1143
1144 private:
1147
1148#ifdef SIP_RUN
1150#endif
1151
1152 QString mFieldName;
1153};
1154
1155
1162class CORE_EXPORT QgsVbScriptVisitor
1163{
1164 public:
1165 virtual ~QgsVbScriptVisitor() = default;
1166
1168 virtual void visit( const QgsVbScriptBlockStatement &node ) = 0;
1170 virtual void visit( const QgsVbScriptVariableDeclarationStatement &node ) = 0;
1172 virtual void visit( const QgsVbScriptAssignmentStatement &node ) = 0;
1174 virtual void visit( const QgsVbScriptFunctionDeclarationStatement &node ) = 0;
1176 virtual void visit( const QgsVbScriptExpressionStatement &node ) = 0;
1178 virtual void visit( const QgsVbScriptLiteralExpression &node ) = 0;
1180 virtual void visit( const QgsVbScriptVariableReferenceExpression &node ) = 0;
1182 virtual void visit( const QgsVbScriptMemberAccessExpression &node ) = 0;
1184 virtual void visit( const QgsVbScriptBinaryOperatorExpression &node ) = 0;
1186 virtual void visit( const QgsVbScriptUnaryOperatorExpression &node ) = 0;
1188 virtual void visit( const QgsVbScriptFunctionCallExpression &node ) = 0;
1190 virtual void visit( const QgsVbScriptIndexExpression &node ) = 0;
1192 virtual void visit( const QgsVbScriptArrayLiteralExpression &node ) = 0;
1194 virtual void visit( const QgsVbScriptIfStatement &node ) = 0;
1196 virtual void visit( const QgsVbScriptForStatement &node ) = 0;
1198 virtual void visit( const QgsVbScriptForEachStatement &node ) = 0;
1200 virtual void visit( const QgsVbScriptWhileStatement &node ) = 0;
1202 virtual void visit( const QgsVbScriptExitStatement &node ) = 0;
1204 virtual void visit( const QgsVbScriptFieldReferenceExpression &node ) = 0;
1205};
1206
1214{
1215 public:
1217
1218 void visit( const QgsVbScriptBlockStatement &node ) override;
1219 void visit( const QgsVbScriptVariableDeclarationStatement &node ) override;
1220 void visit( const QgsVbScriptAssignmentStatement &node ) override;
1221 void visit( const QgsVbScriptFunctionDeclarationStatement &node ) override;
1222 void visit( const QgsVbScriptExpressionStatement &node ) override;
1223 void visit( const QgsVbScriptLiteralExpression &node ) override;
1224 void visit( const QgsVbScriptVariableReferenceExpression &node ) override;
1225 void visit( const QgsVbScriptMemberAccessExpression &node ) override;
1226 void visit( const QgsVbScriptBinaryOperatorExpression &node ) override;
1227 void visit( const QgsVbScriptUnaryOperatorExpression &node ) override;
1228 void visit( const QgsVbScriptFunctionCallExpression &node ) override;
1229 void visit( const QgsVbScriptIndexExpression &node ) override;
1230 void visit( const QgsVbScriptArrayLiteralExpression &node ) override;
1231 void visit( const QgsVbScriptIfStatement &node ) override;
1232 void visit( const QgsVbScriptForStatement &node ) override;
1233 void visit( const QgsVbScriptForEachStatement &node ) override;
1234 void visit( const QgsVbScriptWhileStatement &node ) override;
1235 void visit( const QgsVbScriptExitStatement &node ) override;
1236 void visit( const QgsVbScriptFieldReferenceExpression &node ) override;
1237};
1238
1245class CORE_EXPORT QgsVbScript
1246{
1247 public:
1251 explicit QgsVbScript( const QString &scriptText = QString() );
1252
1253 QgsVbScript( const QgsVbScript &other );
1254 QgsVbScript &operator=( const QgsVbScript &other );
1255
1257
1261 bool hasParserError() const;
1262
1266 QString parserErrorString() const;
1267
1271 const QgsVbScriptBlockStatement *rootBlock() const;
1272
1276 QString script() const;
1277
1281 QString dump() const;
1282
1286 void acceptVisitor( QgsVbScriptVisitor &visitor ) const;
1287
1291 static QString quotedString( const QString &text );
1292
1296 static QString quotedFieldReference( const QString &fieldName );
1297
1301 static QString extractFieldReference( const QString &text );
1302
1303 protected:
1304 std::unique_ptr<QgsVbScriptBlockStatement> mRootBlock;
1305 QString mScript;
1307};
1308
1309#endif // QGSVBSCRIPT_H
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 &parameters, 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.
Definition qgsvbscript.h:58
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.
@ 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"]).
@ 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.
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 mScript
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)
Definition qgis_sip.h:203
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:220