prefixed parser and lexer with hsql_

This commit is contained in:
Pedro 2014-10-31 18:24:47 +01:00
parent 16dbe70ea4
commit 3c69e33d5a
3 changed files with 12 additions and 6 deletions

View File

@ -16,22 +16,22 @@ Statement* SQLParser::parseSQLString(const char *text) {
yyscan_t scanner; yyscan_t scanner;
YY_BUFFER_STATE state; YY_BUFFER_STATE state;
if (yylex_init(&scanner)) { if (hsql_lex_init(&scanner)) {
// couldn't initialize // couldn't initialize
fprintf(stderr, "Error when initializing!\n"); fprintf(stderr, "Error when initializing!\n");
return NULL; return NULL;
} }
state = yy_scan_string(text, scanner); state = hsql__scan_string(text, scanner);
if (yyparse(&stmt, scanner)) { if (hsql_parse(&stmt, scanner)) {
// error parsing // error parsing
fprintf(stderr, "Error when parsing!\n"); fprintf(stderr, "Error when parsing!\n");
return NULL; return NULL;
} }
yy_delete_buffer(state, scanner); hsql__delete_buffer(state, scanner);
yylex_destroy(scanner); hsql_lex_destroy(scanner);
return stmt; return stmt;
} }

View File

@ -35,6 +35,10 @@ int yyerror(Statement **expression, yyscan_t scanner, const char *msg) {
// Tell bison to create a reentrant parser // Tell bison to create a reentrant parser
%define api.pure full %define api.pure full
// Prefix the parser
%define api.prefix {hsql_}
%define api.token.prefix {SQL_}
// Specify code that is included in the generated .h and .c files // Specify code that is included in the generated .h and .c files
%code requires { %code requires {
@ -44,6 +48,8 @@ int yyerror(Statement **expression, yyscan_t scanner, const char *msg) {
typedef void* yyscan_t; typedef void* yyscan_t;
#endif #endif
#define YYSTYPE HSQL_STYPE
} }
// Define additional parameters for yylex (http://www.gnu.org/software/bison/manual/html_node/Pure-Calling.html) // Define additional parameters for yylex (http://www.gnu.org/software/bison/manual/html_node/Pure-Calling.html)
@ -53,7 +59,6 @@ typedef void* yyscan_t;
%parse-param { Statement **statement } %parse-param { Statement **statement }
%parse-param { yyscan_t scanner } %parse-param { yyscan_t scanner }
%define api.token.prefix {SQL_}
/********************************* /*********************************
** Define all data-types (http://www.gnu.org/software/bison/manual/html_node/Union-Decl.html) ** Define all data-types (http://www.gnu.org/software/bison/manual/html_node/Union-Decl.html)

View File

@ -37,6 +37,7 @@
%option noyywrap %option noyywrap
%option warn %option warn
%option case-insensitive %option case-insensitive
%option prefix="hsql_"
/* %option nodefault */ /* %option nodefault */