/src/duckdb/third_party/libpg_query/postgres_parser.cpp
Line | Count | Source |
1 | | #include "postgres_parser.hpp" |
2 | | |
3 | | #include "pg_functions.hpp" |
4 | | #include "parser/parser.hpp" |
5 | | #include "parser/scansup.hpp" |
6 | | #include "common/keywords.hpp" |
7 | | |
8 | | namespace duckdb { |
9 | | |
10 | 328k | PostgresParser::PostgresParser() : success(false), parse_tree(nullptr), error_message(""), error_location(0) {} |
11 | | |
12 | 328k | void PostgresParser::Parse(const std::string &query) { |
13 | 328k | duckdb_libpgquery::pg_parser_init(); |
14 | 328k | duckdb_libpgquery::parse_result res; |
15 | 328k | pg_parser_parse(query.c_str(), &res); |
16 | 328k | success = res.success; |
17 | | |
18 | 328k | if (success) { |
19 | 326k | parse_tree = res.parse_tree; |
20 | 326k | } else { |
21 | 1.45k | error_message = std::string(res.error_message); |
22 | 1.45k | error_location = res.error_location; |
23 | 1.45k | } |
24 | 328k | } |
25 | | |
26 | 0 | vector<duckdb_libpgquery::PGSimplifiedToken> PostgresParser::Tokenize(const std::string &query) { |
27 | 0 | duckdb_libpgquery::pg_parser_init(); |
28 | 0 | auto tokens = duckdb_libpgquery::tokenize(query.c_str()); |
29 | 0 | duckdb_libpgquery::pg_parser_cleanup(); |
30 | 0 | return std::move(tokens); |
31 | 0 | } |
32 | | |
33 | 328k | PostgresParser::~PostgresParser() { |
34 | 328k | duckdb_libpgquery::pg_parser_cleanup(); |
35 | 328k | } |
36 | | |
37 | 103k | duckdb_libpgquery::PGKeywordCategory PostgresParser::IsKeyword(const std::string &text) { |
38 | 103k | return duckdb_libpgquery::is_keyword(text.c_str()); |
39 | 103k | } |
40 | | |
41 | 0 | vector<duckdb_libpgquery::PGKeyword> PostgresParser::KeywordList() { |
42 | | // FIXME: because of this, we might need to change the libpg_query library to use duckdb::vector |
43 | 0 | vector<duckdb_libpgquery::PGKeyword> tmp(duckdb_libpgquery::keyword_list()); |
44 | 0 | return tmp; |
45 | 0 | } |
46 | | |
47 | 328k | void PostgresParser::SetPreserveIdentifierCase(bool preserve) { |
48 | 328k | duckdb_libpgquery::set_preserve_identifier_case(preserve); |
49 | 328k | } |
50 | | |
51 | | } |