HyriseSQLParser/src/parser/SQLParser.cpp

38 lines
809 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>
namespace hsql {
2014-10-09 01:30:22 +02:00
SQLParser::SQLParser() {
fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n");
}
StatementList* SQLParser::parseSQLString(const char *text) {
StatementList* 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;
}
} // namespace hsql