HyriseSQLParser/src/parser/SQLParser.cpp

41 lines
862 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>
// int yyparse(Statement **expression, yyscan_t scanner);
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-10-23 11:41:44 +02:00
Statement* SQLParser::parseSQLString(const char *text) {
2014-10-09 01:30:22 +02:00
Statement* stmt;
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
fprintf(stderr, "Error when initializing!\n");
return NULL;
}
2014-10-31 18:24:47 +01:00
state = hsql__scan_string(text, scanner);
2014-10-09 01:30:22 +02:00
2014-10-31 18:24:47 +01:00
if (hsql_parse(&stmt, scanner)) {
2014-10-09 01:30:22 +02:00
// error parsing
fprintf(stderr, "Error when parsing!\n");
return NULL;
}
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);
2014-10-09 01:30:22 +02:00
return stmt;
}
} // namespace hsql