added an error statement type
This commit is contained in:
parent
71e80cc17e
commit
9002abe81b
|
@ -4,4 +4,5 @@ flex_lexer.h
|
||||||
bison_parser.c*
|
bison_parser.c*
|
||||||
bison_parser.h
|
bison_parser.h
|
||||||
*.o
|
*.o
|
||||||
|
*.output
|
||||||
copy*.sh
|
copy*.sh
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
namespace hsql {
|
namespace hsql {
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
kStmtError,
|
||||||
kStmtSelect,
|
kStmtSelect,
|
||||||
kStmtJoin,
|
kStmtJoin,
|
||||||
kStmtDelete,
|
kStmtDelete,
|
||||||
|
@ -54,7 +55,9 @@ typedef enum {
|
||||||
|
|
||||||
struct Statement {
|
struct Statement {
|
||||||
Statement(StatementType type) : type(type) {};
|
Statement(StatementType type) : type(type) {};
|
||||||
|
|
||||||
StatementType type;
|
StatementType type;
|
||||||
|
const char* parser_msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,8 @@ Statement* SQLParser::parseSQLString(const char *text) {
|
||||||
state = hsql__scan_string(text, scanner);
|
state = hsql__scan_string(text, scanner);
|
||||||
|
|
||||||
if (hsql_parse(&stmt, scanner)) {
|
if (hsql_parse(&stmt, scanner)) {
|
||||||
// error parsing
|
// Returns an error stmt object
|
||||||
// fprintf(stderr, "Error when parsing!\n");
|
return stmt;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hsql__delete_buffer(state, scanner);
|
hsql__delete_buffer(state, scanner);
|
||||||
|
|
|
@ -19,8 +19,9 @@
|
||||||
|
|
||||||
using namespace hsql;
|
using namespace hsql;
|
||||||
|
|
||||||
int yyerror(Statement **expression, yyscan_t scanner, const char *msg) {
|
int yyerror(Statement **stmt, yyscan_t scanner, const char *msg) {
|
||||||
// fprintf(stderr, "[Error] SQL Parser: %s\n", msg);
|
*stmt = new Statement(kStmtError);
|
||||||
|
(*stmt)->parser_msg = msg;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,16 @@ int main(int argc, char *argv[]) {
|
||||||
end = std::chrono::system_clock::now();
|
end = std::chrono::system_clock::now();
|
||||||
std::chrono::duration<double> elapsed_seconds = end-start;
|
std::chrono::duration<double> elapsed_seconds = end-start;
|
||||||
|
|
||||||
if (expectFalse != (stmt == NULL)) {
|
if (expectFalse != (stmt->type == kStmtError)) {
|
||||||
fprintf(stderr, "-> Failed (%.3fms)! \"%s\"\n", elapsed_seconds.count()*1000, sql);
|
fprintf(stderr, "-> Failed (%.3fms)! \"%s\"\n", elapsed_seconds.count()*1000, sql);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
printf("Success (%.3fms%s)! \"%s\"\n", elapsed_seconds.count()*1000, (expectFalse) ? ", expected error" : "", sql);
|
if (expectFalse) {
|
||||||
|
printf("Success (%.3fms)! %s: \"%s\"\n", elapsed_seconds.count()*1000, stmt->parser_msg, sql);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("Success (%.3fms)! \"%s\"\n", elapsed_seconds.count()*1000, sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue