1 #ifndef PARSER_HELPER_STUBS_H 2 #define PARSER_HELPER_STUBS_H 3 4 #include "parsercontext.h" 5 #include "ast/sqlitebegintrans.h" 6 #include "ast/sqlitecreatetable.h" 7 #include "ast/sqliteconflictalgo.h" 8 #include "ast/sqliteselect.h" 9 #include "ast/sqliteindexedcolumn.h" 10 #include "ast/sqliteforeignkey.h" 11 #include "ast/sqliteorderby.h" 12 #include "ast/sqlitewindowdefinition.h" 13 #include "ast/sqlitewith.h" 14 15 #include <QString> 16 #include <QList> 17 18 /** @file 19 * 20 * This file contains only structures and functions 21 * that are helpful in parsers generated by lemon, 22 * because lemon uses C unions, therefore only primitive 23 * types can be used as data type. 24 * (see %type declarations in *.y files). 25 */ 26 27 /** 28 * @brief Stores 'dbnm' grammar rule. 29 */ 30 struct ParserFullName 31 { 32 QString name1 = QString(); 33 QString name2 = QString(); 34 }; 35 36 /** 37 * @brief Stores <tt>EXPLAIN</tt> and <tt>QUERY PLAN</tt> grammar rules. 38 */ 39 struct ParserStubExplain 40 { 41 ParserStubExplain(bool explain, bool queryPlan); 42 43 bool explain; 44 bool queryPlan; 45 }; 46 47 /** 48 * @brief Stores "<tt>OR</tt> conflict" grammar rules. 49 */ 50 struct ParserStubInsertOrReplace 51 { 52 explicit ParserStubInsertOrReplace(bool replace); 53 ParserStubInsertOrReplace(bool replace, SqliteConflictAlgo orConflict); 54 55 bool replace; 56 SqliteConflictAlgo orConflict; 57 }; 58 59 /** 60 * @brief Stores grammar rules for <tt>BEGIN/END/COMMIT/ROLLBACK</tt> additional parameters. 61 */ 62 struct ParserStubTransDetails 63 { 64 QString name = QString(); 65 SqliteBeginTrans::Type type = SqliteBeginTrans::Type::null; 66 bool transactionKw = false; 67 bool toKw = false; 68 SqliteConflictAlgo onConflict = SqliteConflictAlgo::null; 69 }; 70 71 typedef QList<SqliteCreateTable::Column*> ParserCreateTableColumnList; 72 typedef QList<SqliteCreateTable::Constraint*> ParserCreateTableConstraintList; 73 typedef QList<SqliteCreateTable::Column::Constraint*> ParserCreateTableColumnConstraintList; 74 typedef QList<SqliteForeignKey::Condition*> ParserFkConditionList; 75 typedef QList<SqliteExpr*> ParserExprList; 76 typedef QList<SqliteWith::CommonTableExpression*> ParserCteList; 77 typedef QList<SqliteSelect::Core::ResultColumn*> ParserResultColumnList; 78 typedef QList<SqliteSelect::Core::JoinSourceOther*> ParserOtherSourceList; 79 typedef QList<SqliteOrderBy*> ParserOrderByList; 80 typedef QList<SqliteQuery*> ParserQueryList; 81 typedef QPair<QVariant,SqliteExpr*> ParserSetValue; 82 typedef QList<ParserSetValue> ParserSetValueList; 83 typedef QList<SqliteIndexedColumn*> ParserIndexedColumnList; 84 typedef QList<ParserExprList> ParserExprNestedList; 85 typedef QList<SqliteWindowDefinition*> ParserWindowDefList; 86 87 /** 88 * @brief Stores parameters for defferable foreign keys. 89 */ 90 struct ParserDeferSubClause 91 { 92 ParserDeferSubClause(SqliteDeferrable deferrable, SqliteInitially initially); 93 94 SqliteInitially initially; 95 SqliteDeferrable deferrable; 96 }; 97 98 /** 99 * @brief Stores "<tt>AS</tt> aliasName" grammar rule. 100 */ 101 struct ParserStubAlias 102 { 103 ParserStubAlias(const QString& name, bool asKw); 104 105 QString name = QString(); 106 bool asKw = false; 107 }; 108 109 /** 110 * @brief Stores <tt>NOT INDEXED/INDEXED BY</tt> grammar rules. 111 */ 112 struct ParserIndexedBy 113 { 114 explicit ParserIndexedBy(const QString& name); 115 explicit ParserIndexedBy(bool indexedBy); 116 117 bool notIndexedKw = false; 118 QString indexedBy = QString(); 119 }; 120 121 class ParserTermOrLiteral 122 { 123 public: 124 explicit ParserTermOrLiteral(const QString& name); 125 explicit ParserTermOrLiteral(const QVariant& literal); 126 127 QString toName() const; 128 QVariant toLiteral() const; 129 bool isName() const; 130 bool isLiteral() const; 131 132 private: 133 QVariant value; 134 bool nameMode = false; 135 }; 136 137 #endif // PARSER_HELPER_STUBS_H 138