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
|
//===----------------------------------------------------------------------===//
// DuckDB
//
// test_parser.hpp
//
//
//===----------------------------------------------------------------------===//
#pragma once
#include "duckdb.hpp"
#include "duckdb/common/types.hpp"
#include "duckdb/common/exception_format_value.hpp"
#include "sqllogic_command.hpp"
namespace duckdb {
enum class SQLLogicTokenType {
SQLLOGIC_INVALID,
SQLLOGIC_SKIP_IF,
SQLLOGIC_ONLY_IF,
SQLLOGIC_STATEMENT,
SQLLOGIC_QUERY,
SQLLOGIC_HASH_THRESHOLD,
SQLLOGIC_HALT,
SQLLOGIC_MODE,
SQLLOGIC_SET,
SQLLOGIC_RESET,
SQLLOGIC_LOOP,
SQLLOGIC_FOREACH,
SQLLOGIC_CONCURRENT_LOOP,
SQLLOGIC_CONCURRENT_FOREACH,
SQLLOGIC_ENDLOOP,
SQLLOGIC_REQUIRE,
SQLLOGIC_REQUIRE_ENV,
SQLLOGIC_TEST_ENV,
SQLLOGIC_LOAD,
SQLLOGIC_RESTART,
SQLLOGIC_RECONNECT,
SQLLOGIC_SLEEP,
SQLLOGIC_UNZIP,
SQLLOGIC_TAGS,
SQLLOGIC_CONTINUE,
};
class SQLLogicToken {
public:
SQLLogicTokenType type;
vector<string> parameters;
};
class SQLLogicParser {
public:
string file_name;
//! The lines of the current text file
vector<string> lines;
//! The current line number
idx_t current_line = 0;
//! Whether or not the input should be printed to stdout as it is executed
bool print_input = false;
//! Whether or not we have seen a statement
bool seen_statement = false;
public:
static bool EmptyOrComment(const string &line);
static bool IsSingleLineStatement(SQLLogicToken &token);
static bool IsTestCommand(SQLLogicTokenType &type);
//! Does the next line contain a comment, empty line, or is the end of the file
bool NextLineEmptyOrComment();
//! Opens the file, returns whether or not reading was successful
bool OpenFile(const string &path);
//! Moves the current line to the beginning of the next statement
//! Returns false if there is no next statement (i.e. we reached the end of the file)
bool NextStatement();
//! Move to the next line
void NextLine();
//! Extract a statement and move the current_line pointer forward
//! if "is_query" is false, the statement stops at the next empty line
//! if "is_query" is true, the statement stops at the next empty line or the next ----
string ExtractStatement();
//! Extract the expected result
vector<string> ExtractExpectedResult();
//! Extract the expected error (in case of statement error)
string ExtractExpectedError(ExpectedResult expected_result, bool original_sqlite_test);
//! Tokenize the current line
SQLLogicToken Tokenize();
template <typename... Args>
void Fail(const string &msg, Args... params) {
vector<ExceptionFormatValue> values;
FailRecursive(msg, values, params...);
}
private:
SQLLogicTokenType CommandToToken(const string &token);
void FailRecursive(const string &msg, vector<ExceptionFormatValue> &values);
template <class T, typename... Args>
void FailRecursive(const string &msg, vector<ExceptionFormatValue> &values, T param, Args... params) {
values.push_back(ExceptionFormatValue::CreateFormatValue<T>(param));
FailRecursive(msg, values, params...);
}
};
} // namespace duckdb
|