HyriseSQLParser/src/parser/SQLParser.cpp

44 lines
949 B
C++
Raw Normal View History

2014-10-09 01:30:22 +02:00
#include "SQLParser.h"
2014-10-16 15:35:38 +02:00
#include "bison_parser.h"
#include "flex_lexer.h"
2014-10-09 01:30:22 +02:00
#include <stdio.h>
#include <string>
2014-10-09 01:30:22 +02:00
namespace hsql {
2014-10-09 01:30:22 +02:00
SQLParser::SQLParser() {
fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n");
}
2014-12-03 17:43:02 +01:00
SQLStatementList* SQLParser::parseSQLString(const char *text) {
SQLStatementList* result;
2014-10-09 01:30:22 +02:00
yyscan_t scanner;
YY_BUFFER_STATE state;
2014-10-31 18:24:47 +01:00
if (hsql_lex_init(&scanner)) {
2014-10-09 01:30:22 +02:00
// couldn't initialize
2014-11-03 23:57:42 +01:00
fprintf(stderr, "[Error] SQLParser: Error when initializing lexer!\n");
2014-10-09 01:30:22 +02:00
return NULL;
}
2014-10-31 18:24:47 +01:00
state = hsql__scan_string(text, scanner);
2014-10-09 01:30:22 +02:00
if (hsql_parse(&result, scanner)) {
2014-11-04 00:02:40 +01:00
// Returns an error stmt object
return result;
2014-10-09 01:30:22 +02:00
}
2014-10-31 18:24:47 +01:00
hsql__delete_buffer(state, scanner);
2014-10-09 01:30:22 +02:00
2014-10-31 18:24:47 +01:00
hsql_lex_destroy(scanner);
return result;
}
2015-01-07 13:24:39 +01:00
SQLStatementList* SQLParser::parseSQLString(const std::string& text) {
return parseSQLString(text.c_str());
}
} // namespace hsql