aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/parser/parser_helper_stubs.h
blob: ec71f8b69e7d2c174f9ffafa0c6a92821a97ee20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef PARSER_HELPER_STUBS_H
#define PARSER_HELPER_STUBS_H

#include "parsercontext.h"
#include "ast/sqlitebegintrans.h"
#include "ast/sqlitecreatetable.h"
#include "ast/sqliteconflictalgo.h"
#include "ast/sqliteselect.h"
#include "ast/sqliteindexedcolumn.h"
#include "ast/sqliteforeignkey.h"
#include "ast/sqliteorderby.h"
#include "ast/sqlitewindowdefinition.h"
#include "ast/sqlitewith.h"

#include <QString>
#include <QList>

/** @file
 *
 * This file contains only structures and functions
 * that are helpful in parsers generated by lemon,
 * because lemon uses C unions, therefore only primitive
 * types can be used as data type.
 * (see %type declarations in *.y files).
 */

/**
 * @brief Stores 'dbnm' grammar rule.
 */
struct ParserFullName
{
    QString name1 = QString();
    QString name2 = QString();
};

/**
 * @brief Stores <tt>EXPLAIN</tt> and <tt>QUERY PLAN</tt> grammar rules.
 */
struct ParserStubExplain
{
    ParserStubExplain(bool explain, bool queryPlan);

    bool explain;
    bool queryPlan;
};

/**
 * @brief Stores "<tt>OR</tt> conflict" grammar rules.
 */
struct ParserStubInsertOrReplace
{
    explicit ParserStubInsertOrReplace(bool replace);
    ParserStubInsertOrReplace(bool replace, SqliteConflictAlgo orConflict);

    bool replace;
    SqliteConflictAlgo orConflict;
};

/**
 * @brief Stores grammar rules for <tt>BEGIN/END/COMMIT/ROLLBACK</tt> additional parameters.
 */
struct ParserStubTransDetails
{
    QString name = QString();
    SqliteBeginTrans::Type type = SqliteBeginTrans::Type::null;
    bool transactionKw = false;
    bool toKw = false;
    SqliteConflictAlgo onConflict = SqliteConflictAlgo::null;
};

struct ParserStubCreateTableOption
{
    enum Type
    {
        WITHOUT_ROWID,
        STRICT
    };

    ParserStubCreateTableOption(Type type);

    Type type;
};

ParserStubCreateTableOption* parserStubFindCreateTableOption(const QList<ParserStubCreateTableOption*>& options, ParserStubCreateTableOption::Type type);

typedef QList<SqliteCreateTable::Column*> ParserCreateTableColumnList;
typedef QList<SqliteCreateTable::Constraint*> ParserCreateTableConstraintList;
typedef QList<SqliteCreateTable::Column::Constraint*> ParserCreateTableColumnConstraintList;
typedef QList<SqliteForeignKey::Condition*> ParserFkConditionList;
typedef QList<SqliteExpr*> ParserExprList;
typedef QList<SqliteWith::CommonTableExpression*> ParserCteList;
typedef QList<SqliteSelect::Core::ResultColumn*> ParserResultColumnList;
typedef QList<SqliteSelect::Core::JoinSourceOther*> ParserOtherSourceList;
typedef QList<SqliteOrderBy*> ParserOrderByList;
typedef QList<SqliteQuery*> ParserQueryList;
typedef QPair<QVariant,SqliteExpr*> ParserSetValue;
typedef QList<ParserSetValue> ParserSetValueList;
typedef QList<SqliteIndexedColumn*> ParserIndexedColumnList;
typedef QList<ParserExprList> ParserExprNestedList;
typedef QList<SqliteWindowDefinition*> ParserWindowDefList;
typedef QList<ParserStubCreateTableOption*> ParserCreateTableOptionList;

/**
 * @brief Stores parameters for defferable foreign keys.
 */
struct ParserDeferSubClause
{
    ParserDeferSubClause(SqliteDeferrable deferrable, SqliteInitially initially);

    SqliteInitially initially;
    SqliteDeferrable deferrable;
};

/**
 * @brief Stores "<tt>AS</tt> aliasName" grammar rule.
 */
struct ParserStubAlias
{
    ParserStubAlias(const QString& name, bool asKw);

    QString name = QString();
    bool asKw = false;
};

/**
 * @brief Stores <tt>NOT INDEXED/INDEXED BY</tt> grammar rules.
 */
struct ParserIndexedBy
{
    explicit ParserIndexedBy(const QString& name);
    explicit ParserIndexedBy(bool indexedBy);

    bool notIndexedKw = false;
    QString indexedBy = QString();
};

class ParserTermOrLiteral
{
    public:
        explicit ParserTermOrLiteral(const QString& name);
        explicit ParserTermOrLiteral(const QVariant& literal);

        QString toName() const;
        QVariant toLiteral() const;
        bool isName() const;
        bool isLiteral() const;

    private:
        QVariant value;
        bool nameMode = false;
};

#endif // PARSER_HELPER_STUBS_H