1 /* Copyright (C) 2014 InfiniDB, Inc. 2 Copyright (C) 2016 MariaDB Corporation 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; version 2 of 7 the License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 MA 02110-1301, USA. */ 18 19 /*********************************************************************** 20 * $Id: dmlparser.h 9210 2013-01-21 14:10:42Z rdempsey $ 21 * 22 * 23 ***********************************************************************/ 24 /** @file */ 25 26 #ifndef DMLPARSER_H 27 #define DMLPARSER_H 28 29 #include <stdexcept> 30 #include "dmlpkg.h" 31 32 namespace dmlpackage 33 { 34 typedef std::vector<char*> valbuf_t; 35 36 37 typedef SqlStatementList ParseTree; 38 39 // instance data for the parser 40 typedef std::vector<char*> valbuf_t; 41 42 struct scan_data 43 { 44 /* Handles to the buffer that the lexer uses internally */ 45 char* scanbuf; 46 void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp 47 valbuf_t valbuf; 48 }; 49 50 /** @brief BISON parser wrapper class 51 */ 52 class DMLParser 53 { 54 public: 55 /** @brief ctor 56 */ 57 DMLParser(); 58 59 /** @brief dtor 60 */ 61 virtual ~DMLParser(); 62 63 /** @brief parse the supplied dml statement 64 * 65 * @param dmltext the dml statement to parse 66 */ 67 int parse(const char* dmltext); 68 69 /** @brief get the parse tree 70 */ 71 const ParseTree& getParseTree(); 72 73 void setDefaultSchema(std::string schema); 74 75 /** @brief was the parse successful 76 */ 77 bool good(); 78 79 /** @brief put the parser in debug mode so as to dump 80 * diagnostic information 81 */ 82 void setDebug(bool debug); 83 84 protected: 85 ParseTree fParseTree; 86 int fStatus; 87 bool fDebug; 88 void* scanner; // yyscan_t * needed for re-entrant flex scanner 89 scan_data scanData; 90 91 private: 92 93 }; 94 95 /** @brief specialization of the DMLParser class 96 * specifically for reading the dml statement 97 * from a file 98 */ 99 class DMLFileParser : public DMLParser 100 { 101 public: 102 /** @brief ctor 103 */ 104 DMLFileParser(); 105 106 /** @brief parse the dml statement contained in the 107 * supplied file 108 * 109 * @param fileName the fully qualified file name to open 110 * and parse the contents of 111 */ 112 int parse(const std::string& fileName); 113 114 protected: 115 116 private: 117 }; 118 119 } 120 #endif // DMLPARSER_H 121