diff --git a/src/SQLParser.cpp b/src/SQLParser.cpp index 9270745..217db47 100644 --- a/src/SQLParser.cpp +++ b/src/SQLParser.cpp @@ -12,22 +12,22 @@ namespace hsql { fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n"); } - SQLParserResult* SQLParser::parseSQLString(const char* text) { SQLParserResult* result = NULL; yyscan_t scanner; YY_BUFFER_STATE state; if (hsql_lex_init(&scanner)) { - // couldn't initialize + // Couldn't initialize the lexer. fprintf(stderr, "[Error] SQLParser: Error when initializing lexer!\n"); return NULL; } state = hsql__scan_string(text, scanner); + // Parser and return early if it failed. if (hsql_parse(&result, scanner)) { - // Returns an error stmt object + // Returns an error stmt object. return result; } diff --git a/src/SQLParser.h b/src/SQLParser.h index 50c3f18..5bb2a4a 100644 --- a/src/SQLParser.h +++ b/src/SQLParser.h @@ -5,15 +5,18 @@ #include "sql/statements.h" namespace hsql { - /** - * Main class for parsing SQL strings - */ + + // Static methods used to parse SQL strings. class SQLParser { public: + // Parses a given constant character SQL string. static SQLParserResult* parseSQLString(const char* sql); + + // Parses an SQL std::string. static SQLParserResult* parseSQLString(const std::string& sql); private: + // Static class can't be instatiated. SQLParser(); }; diff --git a/src/SQLParserResult.cpp b/src/SQLParserResult.cpp index 52c9f02..ed7e1b5 100644 --- a/src/SQLParserResult.cpp +++ b/src/SQLParserResult.cpp @@ -7,14 +7,12 @@ namespace hsql { isValid(true), errorMsg(NULL) {}; - SQLParserResult::SQLParserResult(SQLStatement* stmt) : isValid(true), errorMsg(NULL) { addStatement(stmt); }; - SQLParserResult::~SQLParserResult() { for (std::vector::iterator it = statements.begin(); it != statements.end(); ++it) { delete *it; @@ -23,17 +21,14 @@ namespace hsql { delete errorMsg; } - void SQLParserResult::addStatement(SQLStatement* stmt) { statements.push_back(stmt); } - SQLStatement* SQLParserResult::getStatement(int id) { return statements[id]; } - size_t SQLParserResult::size() { return statements.size(); } diff --git a/src/SQLParserResult.h b/src/SQLParserResult.h index f06bd27..5622dda 100644 --- a/src/SQLParserResult.h +++ b/src/SQLParserResult.h @@ -4,29 +4,41 @@ #include "sql/SQLStatement.h" namespace hsql { - /** - * Represents the result of the SQLParser. - * If parsing was successful it contains a list of SQLStatement. - */ + // Represents the result of the SQLParser. + // If parsing was successful it contains a list of SQLStatement. class SQLParserResult { public: - + // Initialize with empty statement list. SQLParserResult(); + + // Initialize with a single statement. SQLParserResult(SQLStatement* stmt); + + // Deletes all statements in the resul. virtual ~SQLParserResult(); - void addStatement(SQLStatement* stmt); - - SQLStatement* getStatement(int id); - + // Returns the number of statements in the result. size_t size(); - // public properties + // Gets the SQL statement with the given index. + SQLStatement* getStatement(int id); + + // Adds a statement to the result list of statements. + void addStatement(SQLStatement* stmt); + + // List of statements within the result. std::vector statements; + + // Flag indicating the parsing was successful. bool isValid; + // Error message, if an error occurred. const char* errorMsg; + + // Line number of the occurrance of the error in the query. int errorLine; + + // Column number of the occurrance of the error in the query. int errorColumn; };