QGIS API Documentation 4.3.0-Master (bd2f5e21fd1)
Loading...
Searching...
No Matches
qgsesriarcadescript.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsesriarcadescript.h
3 --------------------
4 begin : October 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 QGSESRIARCADESCRIPT_H
17#define QGSESRIARCADESCRIPT_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
46
59class CORE_EXPORT QgsEsriArcadeNode
60{
61#ifdef SIP_RUN
63 switch ( sipCpp->nodeType() )
64 {
66 sipType = sipType_QgsEsriArcadeBlockStatement;
67 break;
69 sipType = sipType_QgsEsriArcadeVariableDeclarationStatement;
70 break;
72 sipType = sipType_QgsEsriArcadeAssignmentStatement;
73 break;
75 sipType = sipType_QgsEsriArcadeReturnStatement;
76 break;
78 sipType = sipType_QgsEsriArcadeFunctionDeclarationStatement;
79 break;
81 sipType = sipType_QgsEsriArcadeExpressionStatement;
82 break;
84 sipType = sipType_QgsEsriArcadeArrayLiteralExpression;
85 break;
87 sipType = sipType_QgsEsriArcadeLiteralExpression;
88 break;
90 sipType = sipType_QgsEsriArcadeVariableReferenceExpression;
91 break;
93 sipType = sipType_QgsEsriArcadeProfileVariableReferenceExpression;
94 break;
96 sipType = sipType_QgsEsriArcadeMemberAccessExpression;
97 break;
99 sipType = sipType_QgsEsriArcadeBinaryOperatorExpression;
100 break;
102 sipType = sipType_QgsEsriArcadeUnaryOperatorExpression;
103 break;
105 sipType = sipType_QgsEsriArcadeFunctionCallExpression;
106 break;
108 sipType = sipType_QgsEsriArcadeIndexExpression;
109 break;
111 sipType = sipType_QgsEsriArcadeDictionaryLiteralExpression;
112 break;
114 sipType = sipType_QgsEsriArcadeIfStatement;
115 break;
117 sipType = sipType_QgsEsriArcadeForStatement;
118 break;
120 sipType = sipType_QgsEsriArcadeForInStatement;
121 break;
123 sipType = sipType_QgsEsriArcadeWhileStatement;
124 break;
126 sipType = sipType_QgsEsriArcadeBreakStatement;
127 break;
129 sipType = sipType_QgsEsriArcadeContinueStatement;
130 break;
131 default:
132 sipType = nullptr;
133 break;
134 }
135 SIP_END
136#endif
137
138 public:
142 enum class NodeType
143 {
144 BlockStatement,
145 VariableDeclarationStatement,
146 ReturnStatement,
147 AssignmentStatement,
148 FunctionDeclarationStatement,
149 ExpressionStatement,
150 LiteralExpression,
151 VariableReferenceExpression,
152 ProfileVariableReferenceExpression,
153 MemberAccessExpression,
154 BinaryOperatorExpression,
155 UnaryOperatorExpression,
156 FunctionCallExpression,
157 IndexExpression,
158 ArrayLiteralExpression,
159 DictionaryLiteralExpression,
160 IfStatement,
161 ForStatement,
162 ForInStatement,
163 WhileStatement,
164 BreakStatement,
165 ContinueStatement,
166 };
167
168 virtual ~QgsEsriArcadeNode() = default;
169
174
180 virtual QString dump() const = 0;
181
187 virtual QgsEsriArcadeNode *clone() const = 0 SIP_FACTORY;
188
192 virtual void accept( QgsEsriArcadeVisitor &visitor ) const = 0;
193};
194
205{
206 public:
207 ~QgsEsriArcadeStatement() override = default;
208};
209
223{
224 public:
225 ~QgsEsriArcadeExpression() override = default;
226};
227
235{
236 public:
238
244 explicit QgsEsriArcadeBlockStatement( const QList<QgsEsriArcadeStatement *> &statements SIP_TRANSFER );
245
247
249 QString dump() const override;
250 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
251 void accept( QgsEsriArcadeVisitor &visitor ) const override;
252
258 void appendStatement( QgsEsriArcadeStatement *statement SIP_TRANSFER );
259
263 QList<QgsEsriArcadeStatement *> statements() const { return mStatements; }
264
268 int count() const { return mStatements.count(); }
269
270 private:
272 QgsEsriArcadeBlockStatement &operator=( const QgsEsriArcadeBlockStatement &other ) = delete;
273
274#ifdef SIP_RUN
276#endif
277
278 QList<QgsEsriArcadeStatement *> mStatements;
279};
280
290{
291 public:
298
300 QString dump() const override;
301 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
302 void accept( QgsEsriArcadeVisitor &visitor ) const override;
303
309 QString variableName() const { return mVariableName; }
310
317 QgsEsriArcadeExpression *initializer() const { return mInitializer.get(); }
318
319 private:
322
323#ifdef SIP_RUN
325#endif
326
327 QString mVariableName;
328 std::unique_ptr<QgsEsriArcadeExpression> mInitializer;
329};
330
340{
341 public:
346 {
347 Assign,
348 PlusAssign,
349 MinusAssign,
350 MultiplyAssign,
351 DivideAssign,
352 };
353
355 static const char *ASSIGNMENT_OPERATOR_TEXT[] SIP_SKIP;
356
362 QgsEsriArcadeAssignmentStatement( AssignmentOperator assignmentOperator, QgsEsriArcadeExpression *target SIP_TRANSFER, QgsEsriArcadeExpression *value SIP_TRANSFER );
363
365 QString dump() const override;
366 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
367 void accept( QgsEsriArcadeVisitor &visitor ) const override;
368
372 QgsEsriArcadeExpression *target() const { return mTarget.get(); }
373
377 QgsEsriArcadeExpression *value() const { return mValue.get(); }
378
382 AssignmentOperator assignmentOperator() const { return mAssignmentOperator; }
383
384 private:
386 QgsEsriArcadeAssignmentStatement &operator=( const QgsEsriArcadeAssignmentStatement &other ) = delete;
387
388#ifdef SIP_RUN
390#endif
391
392 std::unique_ptr<QgsEsriArcadeExpression> mTarget;
393 std::unique_ptr<QgsEsriArcadeExpression> mValue;
394 AssignmentOperator mAssignmentOperator = AssignmentOperator::Assign;
395};
396
406{
407 public:
414
416 QString dump() const override;
417 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
418 void accept( QgsEsriArcadeVisitor &visitor ) const override;
419
423 QgsEsriArcadeExpression *expression() const { return mExpression.get(); }
424
425 private:
427 QgsEsriArcadeReturnStatement &operator=( const QgsEsriArcadeReturnStatement &other ) = delete;
428
429#ifdef SIP_RUN
431#endif
432
433 std::unique_ptr<QgsEsriArcadeExpression> mExpression;
434};
435
445{
446 public:
453
455 QString dump() const override;
456 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
457 void accept( QgsEsriArcadeVisitor &visitor ) const override;
458
462 QString functionName() const { return mFunctionName; }
463
467 QStringList parameters() const { return mParameters; }
468
472 QgsEsriArcadeBlockStatement *body() const { return mBody.get(); }
473
474 private:
477
478#ifdef SIP_RUN
480#endif
481
482 QString mFunctionName;
483 QStringList mParameters;
484 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
485};
486
498{
499 public:
506
508 QString dump() const override;
509 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
510 void accept( QgsEsriArcadeVisitor &visitor ) const override;
511
515 QgsEsriArcadeExpression *expression() const { return mExpression.get(); }
516
517 private:
519 QgsEsriArcadeExpressionStatement &operator=( const QgsEsriArcadeExpressionStatement &other ) = delete;
520
521#ifdef SIP_RUN
523#endif
524
525 std::unique_ptr<QgsEsriArcadeExpression> mExpression;
526};
527
535{
536 public:
540 explicit QgsEsriArcadeLiteralExpression( const QVariant &value );
541
543 QString dump() const override;
544 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
545 void accept( QgsEsriArcadeVisitor &visitor ) const override;
546
550 QVariant value() const { return mValue; }
551
555 QString valueAsString() const;
556
557 private:
558 QVariant mValue;
559};
560
568{
569 public:
573 explicit QgsEsriArcadeVariableReferenceExpression( const QString &name );
574
576 QString dump() const override;
577 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
578 void accept( QgsEsriArcadeVisitor &visitor ) const override;
579
583 QString name() const { return mName; }
584
585 private:
586 QString mName;
587};
588
598{
599 public:
603 explicit QgsEsriArcadeProfileVariableReferenceExpression( const QString &name );
604
606 QString dump() const override;
607 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
608 void accept( QgsEsriArcadeVisitor &visitor ) const override;
609
613 QString name() const { return mName; }
614
615 private:
616 QString mName;
617};
618
633{
634 public:
641
643 QString dump() const override;
644 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
645 void accept( QgsEsriArcadeVisitor &visitor ) const override;
646
650 QgsEsriArcadeExpression *containerExpression() const { return mContainerExpression.get(); }
651
655 QString memberName() const { return mMemberName; }
656
660 bool isSafeAccess() const { return mIsSafeAccess; }
661
665 void setIsSafeAccess( bool isSafeAccess ) { mIsSafeAccess = isSafeAccess; }
666
667 private:
670
671#ifdef SIP_RUN
673#endif
674
675 std::unique_ptr<QgsEsriArcadeExpression> mContainerExpression;
676 QString mMemberName;
677 bool mIsSafeAccess = false;
678};
679
687{
688 public:
692 enum class BinaryOperator
693 {
694 Plus,
695 Minus,
696 Multiply,
697 Divide,
698 Modulo,
699 Equal,
700 NotEqual,
701 LessThan,
702 GreaterThan,
703 LessThanOrEqual,
704 GreaterThanOrEqual,
705 LogicalAnd,
706 LogicalOr,
707 BitwiseAnd,
708 BitwiseOr,
709 BitwiseXor,
710 BitwiseLeftShift,
711 BitwiseSignedRightShift,
712 BitwiseUnsignedRightShift,
713 };
714
716 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
717
723 QgsEsriArcadeBinaryOperatorExpression( BinaryOperator binaryOperator, QgsEsriArcadeExpression *leftOperand SIP_TRANSFER, QgsEsriArcadeExpression *rightOperand SIP_TRANSFER );
724
726 QString dump() const override;
727 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
728 void accept( QgsEsriArcadeVisitor &visitor ) const override;
729
733 BinaryOperator binaryOperator() const { return mBinaryOperator; }
734
738 QgsEsriArcadeExpression *leftOperand() const { return mLeftOperand.get(); }
739
743 QgsEsriArcadeExpression *rightOperand() const { return mRightOperand.get(); }
744
748 int precedence() const;
749
753 bool leftAssociative() const;
754
758 QString text() const;
759
760 private:
763
764#ifdef SIP_RUN
766#endif
767
768 BinaryOperator mBinaryOperator;
769 std::unique_ptr<QgsEsriArcadeExpression> mLeftOperand;
770 std::unique_ptr<QgsEsriArcadeExpression> mRightOperand;
771};
772
780{
781 public:
785 enum class UnaryOperator
786 {
787 Not,
788 Minus,
789 Plus,
790 BitwiseNot,
791 PreIncrement,
792 PreDecrement,
793 PostIncrement,
794 PostDecrement,
795 };
796
798 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
799
805 QgsEsriArcadeUnaryOperatorExpression( UnaryOperator unaryOperator, QgsEsriArcadeExpression *operand SIP_TRANSFER );
806
808 QString dump() const override;
809 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
810 void accept( QgsEsriArcadeVisitor &visitor ) const override;
811
815 UnaryOperator unaryOperator() const { return mUnaryOperator; }
816
820 QgsEsriArcadeExpression *operand() const { return mOperand.get(); }
821
825 QString text() const;
826
827 private:
830
831#ifdef SIP_RUN
833#endif
834
835 UnaryOperator mUnaryOperator;
836 std::unique_ptr<QgsEsriArcadeExpression> mOperand;
837};
838
848{
849 public:
855 QgsEsriArcadeFunctionCallExpression( const QString &functionName, const QList<QgsEsriArcadeExpression *> &arguments SIP_TRANSFER );
856
858
860 QString dump() const override;
861 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
862 void accept( QgsEsriArcadeVisitor &visitor ) const override;
863
867 QString functionName() const { return mFunctionName; }
868
872 QList<QgsEsriArcadeExpression *> arguments() const { return mArguments; }
873
874 private:
877
878#ifdef SIP_RUN
880#endif
881
882 QString mFunctionName;
883 QList<QgsEsriArcadeExpression *> mArguments;
884};
885
895{
896 public:
903
905 QString dump() const override;
906 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
907 void accept( QgsEsriArcadeVisitor &visitor ) const override;
908
912 QgsEsriArcadeExpression *containerExpression() const { return mContainerExpression.get(); }
913
917 QgsEsriArcadeExpression *indexExpression() const { return mIndexExpression.get(); }
918
919 private:
921 QgsEsriArcadeIndexExpression &operator=( const QgsEsriArcadeIndexExpression &other ) = delete;
922
923#ifdef SIP_RUN
925#endif
926
927 std::unique_ptr<QgsEsriArcadeExpression> mContainerExpression;
928 std::unique_ptr<QgsEsriArcadeExpression> mIndexExpression;
929};
930
942{
943 public:
949 explicit QgsEsriArcadeArrayLiteralExpression( const QList<QgsEsriArcadeExpression *> &elements SIP_TRANSFER );
950
952
954 QString dump() const override;
955 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
956 void accept( QgsEsriArcadeVisitor &visitor ) const override;
957
961 QList<QgsEsriArcadeExpression *> elements() const { return mElements; }
962
963 private:
966
967#ifdef SIP_RUN
969#endif
970
971 QList<QgsEsriArcadeExpression *> mElements;
972};
973
983{
984 public:
991
993
997 QString key() const { return mKey; }
998
1002 QgsEsriArcadeExpression *value() const { return mValue.get(); }
1003
1007 bool isAutoKey() const { return mIsAutoKey; }
1008
1015
1019 QString dump() const;
1020
1021 private:
1023 QgsEsriArcadeDictionaryElement &operator=( const QgsEsriArcadeDictionaryElement &other ) = delete;
1024
1025#ifdef SIP_RUN
1027#endif
1028
1029 QString mKey;
1030 std::unique_ptr<QgsEsriArcadeExpression> mValue;
1031 bool mIsAutoKey = false;
1032};
1033
1043{
1044 public:
1050 explicit QgsEsriArcadeDictionaryLiteralExpression( const QList<QgsEsriArcadeDictionaryElement *> &elements SIP_TRANSFER );
1052
1054 QString dump() const override;
1055 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
1056 void accept( QgsEsriArcadeVisitor &visitor ) const override;
1057
1061 QList<QgsEsriArcadeDictionaryElement *> elements() const { return mElements; }
1062
1063 private:
1066
1067#ifdef SIP_RUN
1069#endif
1070
1071 QList<QgsEsriArcadeDictionaryElement *> mElements;
1072};
1073
1081{
1082 public:
1089
1091 QString dump() const override;
1092 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
1093 void accept( QgsEsriArcadeVisitor &visitor ) const override;
1094
1098 QgsEsriArcadeExpression *condition() const { return mCondition.get(); }
1099
1103 QgsEsriArcadeBlockStatement *trueBlock() const { return mTrueBlock.get(); }
1104
1108 QgsEsriArcadeBlockStatement *falseBlock() const { return mFalseBlock.get(); }
1109
1110 private:
1111 QgsEsriArcadeIfStatement( const QgsEsriArcadeIfStatement &other ) = delete;
1112 QgsEsriArcadeIfStatement &operator=( const QgsEsriArcadeIfStatement &other ) = delete;
1113
1114#ifdef SIP_RUN
1116#endif
1117
1118 std::unique_ptr<QgsEsriArcadeExpression> mCondition;
1119 std::unique_ptr<QgsEsriArcadeBlockStatement> mTrueBlock;
1120 std::unique_ptr<QgsEsriArcadeBlockStatement> mFalseBlock;
1121};
1122
1130{
1131 public:
1139 );
1140
1142 QString dump() const override;
1143 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
1144 void accept( QgsEsriArcadeVisitor &visitor ) const override;
1145
1149 QgsEsriArcadeStatement *initialization() const { return mInitialization.get(); }
1150
1154 QgsEsriArcadeExpression *condition() const { return mCondition.get(); }
1155
1159 QgsEsriArcadeNode *step() const { return mStep.get(); }
1160
1164 QgsEsriArcadeBlockStatement *body() const { return mBody.get(); }
1165
1166 private:
1168 QgsEsriArcadeForStatement &operator=( const QgsEsriArcadeForStatement &other ) = delete;
1169
1170#ifdef SIP_RUN
1172#endif
1173
1174 std::unique_ptr<QgsEsriArcadeStatement> mInitialization;
1175 std::unique_ptr<QgsEsriArcadeExpression> mCondition;
1176 std::unique_ptr<QgsEsriArcadeNode> mStep;
1177 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
1178};
1179
1187{
1188 public:
1192 enum class IterationType
1193 {
1194 ForIn,
1195 ForOf,
1196 };
1197
1204 IterationType iterationType, const QString &variableName, bool isVariableDeclaration, QgsEsriArcadeExpression *collection SIP_TRANSFER, QgsEsriArcadeBlockStatement *body SIP_TRANSFER
1205 );
1206
1208 QString dump() const override;
1209 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
1210 void accept( QgsEsriArcadeVisitor &visitor ) const override;
1211
1215 IterationType iterationType() const { return mIterationType; }
1216
1220 QString variableName() const { return mVariableName; }
1221
1225 bool isVariableDeclaration() const { return mIsVariableDeclaration; }
1226
1230 QgsEsriArcadeExpression *collection() const { return mCollection.get(); }
1231
1235 QgsEsriArcadeBlockStatement *body() const { return mBody.get(); }
1236
1237 private:
1239 QgsEsriArcadeForInStatement &operator=( const QgsEsriArcadeForInStatement &other ) = delete;
1240
1241#ifdef SIP_RUN
1243#endif
1244
1245 IterationType mIterationType = IterationType::ForIn;
1246 QString mVariableName;
1247 bool mIsVariableDeclaration = false;
1248 std::unique_ptr<QgsEsriArcadeExpression> mCollection;
1249 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
1250};
1251
1259{
1260 public:
1267
1269 QString dump() const override;
1270 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
1271 void accept( QgsEsriArcadeVisitor &visitor ) const override;
1272
1276 QgsEsriArcadeExpression *condition() const { return mCondition.get(); }
1277
1281 QgsEsriArcadeBlockStatement *body() const { return mBody.get(); }
1282
1283 private:
1285 QgsEsriArcadeWhileStatement &operator=( const QgsEsriArcadeWhileStatement &other ) = delete;
1286
1287#ifdef SIP_RUN
1289#endif
1290
1291 std::unique_ptr<QgsEsriArcadeExpression> mCondition;
1292 std::unique_ptr<QgsEsriArcadeBlockStatement> mBody;
1293};
1294
1302{
1303 public:
1308
1310 QString dump() const override;
1311 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
1312 void accept( QgsEsriArcadeVisitor &visitor ) const override;
1313};
1314
1322{
1323 public:
1328
1330 QString dump() const override;
1331 QgsEsriArcadeNode *clone() const override SIP_FACTORY;
1332 void accept( QgsEsriArcadeVisitor &visitor ) const override;
1333};
1334
1335
1342class CORE_EXPORT QgsEsriArcadeVisitor
1343{
1344 public:
1345 virtual ~QgsEsriArcadeVisitor() = default;
1346
1348 virtual void visit( const QgsEsriArcadeBlockStatement &node ) = 0;
1350 virtual void visit( const QgsEsriArcadeVariableDeclarationStatement &node ) = 0;
1352 virtual void visit( const QgsEsriArcadeAssignmentStatement &node ) = 0;
1354 virtual void visit( const QgsEsriArcadeReturnStatement &node ) = 0;
1356 virtual void visit( const QgsEsriArcadeFunctionDeclarationStatement &node ) = 0;
1358 virtual void visit( const QgsEsriArcadeExpressionStatement &node ) = 0;
1360 virtual void visit( const QgsEsriArcadeLiteralExpression &node ) = 0;
1362 virtual void visit( const QgsEsriArcadeVariableReferenceExpression &node ) = 0;
1366 virtual void visit( const QgsEsriArcadeMemberAccessExpression &node ) = 0;
1368 virtual void visit( const QgsEsriArcadeBinaryOperatorExpression &node ) = 0;
1370 virtual void visit( const QgsEsriArcadeUnaryOperatorExpression &node ) = 0;
1372 virtual void visit( const QgsEsriArcadeFunctionCallExpression &node ) = 0;
1374 virtual void visit( const QgsEsriArcadeIndexExpression &node ) = 0;
1376 virtual void visit( const QgsEsriArcadeDictionaryLiteralExpression &node ) = 0;
1378 virtual void visit( const QgsEsriArcadeArrayLiteralExpression &node ) = 0;
1380 virtual void visit( const QgsEsriArcadeIfStatement &node ) = 0;
1382 virtual void visit( const QgsEsriArcadeForStatement &node ) = 0;
1384 virtual void visit( const QgsEsriArcadeForInStatement &node ) = 0;
1386 virtual void visit( const QgsEsriArcadeWhileStatement &node ) = 0;
1388 virtual void visit( const QgsEsriArcadeBreakStatement &node ) = 0;
1390 virtual void visit( const QgsEsriArcadeContinueStatement &node ) = 0;
1391};
1392
1400{
1401 public:
1403
1404 void visit( const QgsEsriArcadeBlockStatement &node ) override;
1405 void visit( const QgsEsriArcadeVariableDeclarationStatement &node ) override;
1406 void visit( const QgsEsriArcadeAssignmentStatement &node ) override;
1407 void visit( const QgsEsriArcadeReturnStatement &node ) override;
1408 void visit( const QgsEsriArcadeFunctionDeclarationStatement &node ) override;
1409 void visit( const QgsEsriArcadeExpressionStatement &node ) override;
1410 void visit( const QgsEsriArcadeLiteralExpression &node ) override;
1411 void visit( const QgsEsriArcadeVariableReferenceExpression &node ) override;
1412 void visit( const QgsEsriArcadeProfileVariableReferenceExpression &node ) override;
1413 void visit( const QgsEsriArcadeMemberAccessExpression &node ) override;
1414 void visit( const QgsEsriArcadeBinaryOperatorExpression &node ) override;
1415 void visit( const QgsEsriArcadeUnaryOperatorExpression &node ) override;
1416 void visit( const QgsEsriArcadeFunctionCallExpression &node ) override;
1417 void visit( const QgsEsriArcadeIndexExpression &node ) override;
1418 void visit( const QgsEsriArcadeArrayLiteralExpression &node ) override;
1419 void visit( const QgsEsriArcadeDictionaryLiteralExpression &node ) override;
1420 void visit( const QgsEsriArcadeIfStatement &node ) override;
1421 void visit( const QgsEsriArcadeForStatement &node ) override;
1422 void visit( const QgsEsriArcadeForInStatement &node ) override;
1423 void visit( const QgsEsriArcadeWhileStatement &node ) override;
1424 void visit( const QgsEsriArcadeBreakStatement &node ) override;
1425 void visit( const QgsEsriArcadeContinueStatement &node ) override;
1426};
1427
1434class CORE_EXPORT QgsEsriArcadeScript
1435{
1436 public:
1440 explicit QgsEsriArcadeScript( const QString &scriptText = QString() );
1441
1444
1446
1450 bool hasParserError() const;
1451
1455 QString parserErrorString() const;
1456
1461
1465 QString script() const;
1466
1470 QString dump() const;
1471
1475 void acceptVisitor( QgsEsriArcadeVisitor &visitor ) const;
1476
1480 static QString quotedString( const QString &text );
1481
1482 protected:
1483 std::unique_ptr<QgsEsriArcadeBlockStatement> mRootBlock;
1484 QString mScript;
1486};
1487
1488#endif // QGSESRIARCADESCRIPT_H
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.
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.
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 &parameters, 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.
@ 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.
@ ProfileVariableReferenceExpression
Reference to a profile variable (eg $feature).
@ DictionaryLiteralExpression
A literal dictionary, eg {key: 1, other_key: 2}.
@ VariableDeclarationStatement
Variable declaration statement.
@ MemberAccessExpression
Member access via bracket or notation (eg $feature.ATTRIBUTE or $feature["ATTRIBUTE"]).
@ VariableReferenceExpression
Reference to a standard variable.
@ FunctionDeclarationStatement
Function declaration.
@ 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.
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.
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)
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