Start of new ANTLR4 based parser.
Very simple tests pass.
This commit is contained in:
parent
03b4194193
commit
fbbe832a05
44 changed files with 860 additions and 8 deletions
9
pglablib/sqlast/ColumnDefinition.cpp
Normal file
9
pglablib/sqlast/ColumnDefinition.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include "ColumnDefinition.h"
|
||||
#include "TypeSpecification.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
ColumnDefinition::ColumnDefinition()
|
||||
{
|
||||
|
||||
}
|
||||
28
pglablib/sqlast/ColumnDefinition.h
Normal file
28
pglablib/sqlast/ColumnDefinition.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class TypeSpecification;
|
||||
|
||||
/// Defines the details of a table column
|
||||
///
|
||||
/// Constraints are not included here, as we handle constraints can apply to multiple columns
|
||||
/// and we want to put them all in one place. The UI and SQL generator is allowed to display
|
||||
/// column specific constraints with the column they belong to.
|
||||
class ColumnDefinition : public Node
|
||||
{
|
||||
public:
|
||||
ColumnDefinition();
|
||||
|
||||
private:
|
||||
QString name;
|
||||
std::unique_ptr<TypeSpecification> typeName;
|
||||
bool notNull = true;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
8
pglablib/sqlast/CreateTable.cpp
Normal file
8
pglablib/sqlast/CreateTable.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "CreateTable.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
CreateTable::CreateTable()
|
||||
{
|
||||
|
||||
}
|
||||
21
pglablib/sqlast/CreateTable.h
Normal file
21
pglablib/sqlast/CreateTable.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "Statement.h"
|
||||
#include <memory>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class ColumnDefinition;
|
||||
class TableConstraint;
|
||||
|
||||
class CreateTable: public Statement
|
||||
{
|
||||
public:
|
||||
CreateTable();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
8
pglablib/sqlast/Expression.cpp
Normal file
8
pglablib/sqlast/Expression.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "Expression.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
Expression::Expression()
|
||||
{
|
||||
|
||||
}
|
||||
13
pglablib/sqlast/Expression.h
Normal file
13
pglablib/sqlast/Expression.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class Expression: public Node
|
||||
{
|
||||
public:
|
||||
Expression();
|
||||
};
|
||||
|
||||
}
|
||||
8
pglablib/sqlast/Literal.cpp
Normal file
8
pglablib/sqlast/Literal.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "Literal.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
Literal::Literal()
|
||||
{
|
||||
|
||||
}
|
||||
13
pglablib/sqlast/Literal.h
Normal file
13
pglablib/sqlast/Literal.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "Expression.h"
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class Literal: public Expression
|
||||
{
|
||||
public:
|
||||
Literal();
|
||||
};
|
||||
|
||||
}
|
||||
8
pglablib/sqlast/Node.cpp
Normal file
8
pglablib/sqlast/Node.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "Node.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
Node::Node()
|
||||
{
|
||||
|
||||
}
|
||||
24
pglablib/sqlast/Node.h
Normal file
24
pglablib/sqlast/Node.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class Node {
|
||||
public:
|
||||
Node();
|
||||
virtual ~Node() = default;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
- Node
|
||||
- INSERT
|
||||
- UPDATE
|
||||
- DELETE
|
||||
- SELECT
|
||||
- WITH
|
||||
- CTE
|
||||
|
||||
|
||||
*/
|
||||
13
pglablib/sqlast/SelectItem.cpp
Normal file
13
pglablib/sqlast/SelectItem.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "SelectItem.h"
|
||||
#include "Expression.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
SelectItem::SelectItem(std::unique_ptr<sqlast::Expression> expr)
|
||||
: expression(std::move(expr))
|
||||
{}
|
||||
|
||||
void SelectItem::SetAlias(const std::string &alias)
|
||||
{
|
||||
this->alias = alias;
|
||||
}
|
||||
25
pglablib/sqlast/SelectItem.h
Normal file
25
pglablib/sqlast/SelectItem.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class Expression;
|
||||
|
||||
class SelectItem : public Node
|
||||
{
|
||||
public:
|
||||
explicit SelectItem(std::unique_ptr<sqlast::Expression> expr);
|
||||
|
||||
Expression& GetExpression() { return *expression; }
|
||||
|
||||
void SetAlias(const std::string &alias);
|
||||
std::string GetAlias() const { return alias; }
|
||||
private:
|
||||
std::unique_ptr<Expression> expression;
|
||||
std::string alias;
|
||||
};
|
||||
|
||||
}
|
||||
18
pglablib/sqlast/SelectList.cpp
Normal file
18
pglablib/sqlast/SelectList.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "SelectList.h"
|
||||
#include "SelectItem.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
SelectList::SelectList()
|
||||
{
|
||||
}
|
||||
|
||||
void SelectList::Add(std::unique_ptr<SelectItem> select_item)
|
||||
{
|
||||
list.push_back(std::move(select_item));
|
||||
}
|
||||
|
||||
int SelectList::Count() const
|
||||
{
|
||||
return static_cast<int>(list.size());
|
||||
}
|
||||
29
pglablib/sqlast/SelectList.h
Normal file
29
pglablib/sqlast/SelectList.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class SelectItem;
|
||||
|
||||
class SelectList : public Node
|
||||
{
|
||||
public:
|
||||
SelectList();
|
||||
|
||||
void Add(std::unique_ptr<SelectItem> select_item);
|
||||
int Count() const;
|
||||
|
||||
SelectItem& Get(int index)
|
||||
{
|
||||
return *list.at(index);
|
||||
}
|
||||
private:
|
||||
using List = std::vector<std::unique_ptr<SelectItem>>;
|
||||
|
||||
List list;
|
||||
};
|
||||
|
||||
}
|
||||
19
pglablib/sqlast/SelectStatement.cpp
Normal file
19
pglablib/sqlast/SelectStatement.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "SelectStatement.h"
|
||||
#include "SelectList.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
SelectStatement::SelectStatement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SelectList* SelectStatement::GetSelectList()
|
||||
{
|
||||
return selectList.get();
|
||||
}
|
||||
|
||||
void SelectStatement::SetSelectList(std::unique_ptr<SelectList> value)
|
||||
{
|
||||
selectList = std::move(value);
|
||||
}
|
||||
22
pglablib/sqlast/SelectStatement.h
Normal file
22
pglablib/sqlast/SelectStatement.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "Statement.h"
|
||||
#include <memory>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class SelectList;
|
||||
|
||||
class SelectStatement: public Statement
|
||||
{
|
||||
public:
|
||||
SelectStatement();
|
||||
|
||||
SelectList* GetSelectList();
|
||||
void SetSelectList(std::unique_ptr<SelectList> value);
|
||||
|
||||
private:
|
||||
std::unique_ptr<SelectList> selectList;
|
||||
};
|
||||
|
||||
}
|
||||
10
pglablib/sqlast/Statement.cpp
Normal file
10
pglablib/sqlast/Statement.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "Statement.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
Statement::Statement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
13
pglablib/sqlast/Statement.h
Normal file
13
pglablib/sqlast/Statement.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class Statement: public Node
|
||||
{
|
||||
public:
|
||||
Statement();
|
||||
};
|
||||
|
||||
}
|
||||
24
pglablib/sqlast/StatementList.cpp
Normal file
24
pglablib/sqlast/StatementList.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "StatementList.h"
|
||||
#include "Statement.h"
|
||||
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
StatementList::StatementList()
|
||||
{}
|
||||
|
||||
void StatementList::Add(std::unique_ptr<Statement> &&statement)
|
||||
{
|
||||
statements.push_back(std::move(statement));
|
||||
}
|
||||
|
||||
Statement &StatementList::Get(int index)
|
||||
{
|
||||
return *statements[index];
|
||||
}
|
||||
|
||||
int StatementList::Count() const
|
||||
{
|
||||
return static_cast<int>(statements.size());
|
||||
}
|
||||
|
||||
27
pglablib/sqlast/StatementList.h
Normal file
27
pglablib/sqlast/StatementList.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class Statement;
|
||||
|
||||
class StatementList: public Node
|
||||
{
|
||||
public:
|
||||
StatementList();
|
||||
|
||||
void Add(std::unique_ptr<Statement> &&statement);
|
||||
Statement &Get(int index);
|
||||
int Count() const;
|
||||
|
||||
private:
|
||||
using Statements = std::vector<std::unique_ptr<Statement>>;
|
||||
|
||||
Statements statements;
|
||||
};
|
||||
|
||||
}
|
||||
7
pglablib/sqlast/StringLiteral.cpp
Normal file
7
pglablib/sqlast/StringLiteral.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include "StringLiteral.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
StringLiteral::StringLiteral(const std::string s)
|
||||
: value(QString::fromStdString(s))
|
||||
{}
|
||||
19
pglablib/sqlast/StringLiteral.h
Normal file
19
pglablib/sqlast/StringLiteral.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include "Literal.h"
|
||||
#include <QString>
|
||||
#include <string>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class StringLiteral : public Literal
|
||||
{
|
||||
public:
|
||||
explicit StringLiteral(const std::string s);
|
||||
|
||||
QString GetValue() const { return value; }
|
||||
private:
|
||||
QString value;
|
||||
};
|
||||
|
||||
}
|
||||
8
pglablib/sqlast/TypeSpecification.cpp
Normal file
8
pglablib/sqlast/TypeSpecification.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "TypeSpecification.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
TypeSpecification::TypeSpecification()
|
||||
{
|
||||
|
||||
}
|
||||
23
pglablib/sqlast/TypeSpecification.h
Normal file
23
pglablib/sqlast/TypeSpecification.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
#include <QString>
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
/// These object define not only the base type, but also
|
||||
/// parameters used with the type
|
||||
/// Think the precision of numeric, max length of char, array
|
||||
class TypeSpecification : public Node
|
||||
{
|
||||
public:
|
||||
TypeSpecification();
|
||||
|
||||
private:
|
||||
/// We do not use the PgType from the catalog here as the type used might be defined
|
||||
/// inside the script and not present yet in the catalog.
|
||||
QString baseType;
|
||||
// is_array
|
||||
};
|
||||
|
||||
}
|
||||
8
pglablib/sqlast/Visitor.cpp
Normal file
8
pglablib/sqlast/Visitor.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "Visitor.h"
|
||||
|
||||
using namespace sqlast;
|
||||
|
||||
Visitor::Visitor()
|
||||
{
|
||||
|
||||
}
|
||||
13
pglablib/sqlast/Visitor.h
Normal file
13
pglablib/sqlast/Visitor.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
namespace sqlast {
|
||||
|
||||
class Visitor
|
||||
{
|
||||
public:
|
||||
Visitor();
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
12
pglablib/sqlast/sqlast.h
Normal file
12
pglablib/sqlast/sqlast.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "Node.h"
|
||||
#include "SelectStatement.h"
|
||||
#include "SelectItem.h"
|
||||
#include "SelectList.h"
|
||||
#include "Statement.h"
|
||||
#include "StatementList.h"
|
||||
#include "StringLiteral.h"
|
||||
#undef emit
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue