librostlab-blast  1.0.1
blast-parser-driver.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Laszlo Kajan, Technical University of Munich, Germany
3 
4  This file is part of librostlab.
5 
6  librostlab is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef ROSTLAB_BLAST_PARSER_DRIVER_H
20 #define ROSTLAB_BLAST_PARSER_DRIVER_H 1
21 
22 #include <stdio.h>
23 #include <string>
24 #include <map>
25 #include <rostlab/rostlab_stdexcept.h>
27 #include "rostlab/blast-result.h"
28 
29 // Tell Flex the lexer's prototype ...
30 #define YY_DECL \
31  rostlab::blast::parser::token_type \
32  yylex( rostlab::blast::parser::semantic_type* __yylval, \
33  rostlab::blast::parser::location_type* __yylloc, \
34  rostlab::blast::parser_driver& __drv, \
35  void* yyscanner )
36 // ... and declare it for the parser's sake.
38 #define YY_DECL_FRIEND \
39  rostlab::blast::parser::token_type \
40  ::yylex( rostlab::blast::parser::semantic_type* __yylval, \
41  rostlab::blast::parser::location_type* __yylloc, \
42  rostlab::blast::parser_driver& __drv, \
43  void* yyscanner )
44 
45 namespace rostlab {
46 
47 namespace blast {
48 
49 class parser_error : public rostlab::runtime_error
50 {
51  public:
52  parser_error( const std::string& __msg ) : rostlab::runtime_error(__msg){}
53 };
54 
56 
60  friend class rostlab::blast::parser;
61  friend YY_DECL_FRIEND;
62  public:
64  private:
65  std::string _istream_name; // a name for error reporting
66  FILE* _istream;
67  result_type _result;
68  void* _scanner; // yyscan_t
69  private:
70  // this is a resource - disable copy contructor and copy assignment
71  parser_driver( const parser_driver& ){};
72  parser_driver& operator=(const parser_driver&){return *this;};
73 
74  std::string _buffer;
75  int _n1, _n2;
76  void _scan_init();
77  void _scan_destroy();
78  public:
79  parser_driver( FILE* __istream = stdin, const std::string& __istream_name = "stdin" ) : _istream_name(__istream_name), _istream(__istream)
80  {
81  _scan_init();
82  }
83  virtual ~parser_driver()
84  {
85  _scan_destroy();
86  }
87 
89 
90  const result_type&
91  parse( bool __trace_parsing = false, bool __trace_scanning = false ) throw (rostlab::blast::parser_error);
92 
94  bool trace_scanning();
96  void trace_scanning( bool __b );
97 
99  void error( const rostlab::blast::location& __loc, const std::string __msg )
100  {
101  std::cerr << __loc << ": " << __msg << "\n";
102  }
103 
105  void error( const std::string __msg )
106  {
107  std::cerr << __msg << "\n";
108  }
109 
111 
112  const result_type&
113  result() const { return _result; }
114 };
115 
116 } // namespace blast
117 
118 } // namespace rostlab
119 
120 #endif // ROSTLAB_BLAST_PARSER_DRIVER_H
121 
122 // vim:et:ts=4:ai:
const result_type & result() const
Read-only access to results.
#define YY_DECL_FRIEND
#define YY_DECL
void error(const std::string __msg)
Print error message.
const result_type & parse(bool __trace_parsing=false, bool __trace_scanning=false)
Parse one result from the input stream.
Blast result for one query.
Definition: blast-result.h:165
void error(const rostlab::blast::location &__loc, const std::string __msg)
Print error message for given location.
parser_driver(FILE *__istream=stdin, const std::string &__istream_name="stdin")
parser_error(const std::string &__msg)
bool trace_scanning()
Get tracing of scanning.
rostlab::blast::result result_type
Blast (default, -m 0) output parser.