librostlab-blast  1.0.0
rostlab/blast-parser-driver.h
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2011 Laszlo Kajan, Technical University of Munich, Germany
00003 
00004     This file is part of librostlab.
00005 
00006     librostlab is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public License
00017     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #ifndef ROSTLAB_BLAST_PARSER_DRIVER_H
00020 #define ROSTLAB_BLAST_PARSER_DRIVER_H 1
00021 
00022 #include <stdio.h>
00023 #include <string>
00024 #include <map>
00025 #include <rostlab/rostlab_stdexcept.h>
00026 #include "rostlab/blast-parser-parser.h"
00027 #include "rostlab/blast-result.h"
00028 
00029 // Tell Flex the lexer's prototype ...
00030 #define YY_DECL                                             \
00031   rostlab::blast::parser::token_type                        \
00032   yylex( rostlab::blast::parser::semantic_type* __yylval,   \
00033          rostlab::blast::parser::location_type* __yylloc,   \
00034          rostlab::blast::parser_driver& __drv,              \
00035          void* yyscanner )
00036 // ... and declare it for the parser's sake.
00037 YY_DECL;
00038 #define YY_DECL_FRIEND                                      \
00039   rostlab::blast::parser::token_type                        \
00040   ::yylex( rostlab::blast::parser::semantic_type* __yylval, \
00041          rostlab::blast::parser::location_type* __yylloc,   \
00042          rostlab::blast::parser_driver& __drv,              \
00043          void* yyscanner )
00044 
00045 namespace rostlab {
00046 
00047 namespace blast {
00048 
00049 class parser_error : public rostlab::runtime_error
00050 {
00051   public:
00052                   parser_error( const std::string& __msg ) : rostlab::runtime_error(__msg){}
00053 };
00054 
00056 
00059 class parser_driver {
00060     friend class rostlab::blast::parser;
00061     friend YY_DECL_FRIEND;
00062   public:
00063     typedef       rostlab::blast::result    result_type;
00064   private:
00065     std::string   _istream_name; // a name for error reporting
00066     FILE*         _istream;
00067     result_type   _result;
00068     void*         _scanner; // yyscan_t
00069   private:
00070     // this is a resource - disable copy contructor and copy assignment
00071                   parser_driver( const parser_driver& ){};
00072     parser_driver& operator=(const parser_driver&){return *this;};
00073 
00074     std::string   _buffer;
00075     int           _n1, _n2;
00076     void          _scan_init();
00077     void          _scan_destroy();
00078   public:
00079     parser_driver( FILE* __istream = stdin, const std::string& __istream_name = "stdin" ) : _istream_name(__istream_name), _istream(__istream)
00080     {
00081       _scan_init();
00082     }
00083     virtual ~parser_driver()
00084     {
00085       _scan_destroy();
00086     }
00087 
00089 
00090     const result_type&
00091                   parse( bool __trace_parsing = false, bool __trace_scanning = false ) throw (rostlab::blast::parser_error);
00092 
00094     bool          trace_scanning();
00096     void          trace_scanning( bool __b );
00097 
00099     void          error( const rostlab::blast::location& __loc, const std::string __msg )
00100     {
00101       std::cerr << __loc << ": " << __msg << "\n";
00102     }
00103 
00105     void          error( const std::string __msg )
00106     {
00107       std::cerr << __msg << "\n";
00108     }
00109 
00111 
00112     const result_type&
00113                   result() const { return _result; }
00114 };
00115 
00116 } // namespace blast
00117 
00118 } // namespace rostlab
00119 
00120 #endif // ROSTLAB_BLAST_PARSER_DRIVER_H
00121 
00122 // vim:et:ts=4:ai:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines