Skip to content
Snippets Groups Projects
Commit b66b1e14 authored by Thomas Blum's avatar Thomas Blum
Browse files

Extend parser for Copy Statement

parent 3d72044a
No related branches found
No related tags found
1 merge request!8Feature add copy statement
Pipeline #39198 failed
......@@ -92,6 +92,14 @@ namespace tardisParser {
Branch,
Copy,
CopyTable,
CopyFrom,
CopyPath,
CopyWith,
CopyFormat,
CopyType,
Done
} state_t;
......@@ -140,6 +148,11 @@ namespace tardisParser {
Table relation;
std::vector<std::pair<Column,std::string>> selections;
};
struct CopyStatement {
Table relation;
std::string filePath;
std::string format;
};
using BindingAttribute = std::pair<std::string, std::string>; // bindingName and attribute
......@@ -148,7 +161,7 @@ namespace tardisParser {
State state;
enum OpType : unsigned int {
Unkown, Select, Insert, Update, Delete, CreateTable, CreateBranch, Branch
Unkown, Select, Insert, Update, Delete, CreateTable, CreateBranch, Branch, Copy
} opType;
CreateTableStatement *createTableStmt;
......@@ -157,6 +170,7 @@ namespace tardisParser {
SelectStatement *selectStmt;
UpdateStatement *updateStmt;
DeleteStatement *deleteStmt;
CopyStatement *copyStmt;
ParsingContext() {
opType = Unkown;
......@@ -185,6 +199,9 @@ namespace tardisParser {
break;
case Branch:
break;
case Copy:
delete copyStmt;
break;
}
}
......@@ -202,7 +219,8 @@ namespace tardisParser {
State::CreateTableRelationName,
State::CreateTableColumnsEnd,
State::CreateBranchParent,
State::Branch };
State::Branch,
State::CopyType };
return finalStates.count(state);
}
......
......@@ -36,8 +36,12 @@ namespace tardisParser {
const std::string Branch = "branch";
const std::string Copy = "copy";
const std::string With = "with";
const std::string Format = "format";
static std::set<std::string> keywordset = {Version, Select, From, Where, And, Insert, Into, Values, Update, Set, Delete, Create,
Table, Not, Null, Branch};
Table, Not, Null, Branch, Copy, With, Format};
}
// Define all control symbols
......
......@@ -51,8 +51,61 @@ namespace tardisParser {
} else if (token.equalsKeyword(Keyword::Branch)) {
context.opType = ParsingContext::OpType::Branch;
context.state = State::Branch;
} else if (token.equalsKeyword(Keyword::Copy)) {
context.opType = ParsingContext::OpType::Copy;
context.copyStmt = new CopyStatement();
context.state = State::Copy;
} else {
throw syntactical_error("Expected 'Select', 'Insert', 'Update', 'Delete' , 'BRANCH' or 'Create', found '" + token.value + "'");
throw syntactical_error("Expected 'Select', 'Insert', 'Update', 'Delete' , 'BRANCH', 'COPY' or 'Create', found '" + token.value + "'");
}
break;
//
// Copy
//
case State::Copy:
if (token.hasType(Type::identifier)) {
context.copyStmt->relation.name = token.value;
context.state = State::CopyTable;
} else {
throw syntactical_error("Expected table name, found '" + token.value + "'");
}
break;
case State::CopyTable:
if (token.equalsKeyword(Keyword::From)) {
context.state = State::CopyFrom;
} else {
throw syntactical_error("Expected 'FROM', found '" + token.value + "'");
}
break;
case State::CopyFrom:
if (token.hasType(Type::identifier)) {
context.copyStmt->filePath = token.value;
context.state = State::CopyPath;
} else {
throw syntactical_error("Expected file path, found '" + token.value + "'");
}
break;
case State::CopyPath:
if (token.equalsKeyword(Keyword::With)) {
context.state = State::CopyWith;
} else {
throw syntactical_error("Expected 'WITH', found '" + token.value + "'");
}
break;
case State::CopyWith:
if (token.equalsKeyword(Keyword::Format)) {
context.state = State::CopyFormat;
} else {
throw syntactical_error("Expected 'FORMAT', found '" + token.value + "'");
}
break;
case State::CopyFormat:
if (token.hasType(Type::identifier)) {
context.copyStmt->format = token.value;
context.state = State::CopyType;
} else {
throw syntactical_error("Expected format name, found '" + token.value + "'");
}
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment