-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSQLParser.cpp
More file actions
47 lines (34 loc) · 1.08 KB
/
SQLParser.cpp
File metadata and controls
47 lines (34 loc) · 1.08 KB
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
#include "SQLParser.h"
#include "parser/bison_parser.h"
#include "parser/flex_lexer.h"
#include <stdio.h>
#include <string>
namespace hsql {
SQLParser::SQLParser() {
fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n");
}
SQLParserResult* SQLParser::parseSQLString(const char* text) {
SQLParserResult* result = NULL;
yyscan_t scanner;
YY_BUFFER_STATE state;
if (hsql_lex_init(&scanner)) {
// Couldn't initialize the lexer.
fprintf(stderr, "[Error] SQLParser: Error when initializing lexer!\n");
return NULL;
}
state = hsql__scan_string(text, scanner);
// Parser and return early if it failed.
if (hsql_parse(&result, scanner)) {
// Returns an error stmt object.
hsql__delete_buffer(state, scanner);
hsql_lex_destroy(scanner);
return result;
}
hsql__delete_buffer(state, scanner);
hsql_lex_destroy(scanner);
return result;
}
SQLParserResult* SQLParser::parseSQLString(const std::string& text) {
return parseSQLString(text.c_str());
}
} // namespace hsql