Debian Codegraph @

FaCT++.Python/lib/FaCT++/comparser.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef COMPARSER_H
21 #define COMPARSER_H
22
23 #include "comscanner.h"
24
25 /// generic class for parsing with usage of scanner derived from CommonScanner
26 template <typename Scanner>
27 class CommonParser
28 {
29 protected: // members
30 /// used scanner
31 Scanner scan;
32 /// last scanned token
33 GenericToken Current;
34
35 protected: // methods
36 /// get current token
37 GenericToken Code ( void ) const { return Current; }
38 /// receive (and save) next token
39 void NextLex ( void ) { Current = scan.GetLex(); }
40 /// ensure that current token has given value; return error if it's not a case
41 void MustBe ( GenericToken t, const char* message = nullptr ) const
42 {
43 if ( Current != t )
44 scan.error(message);
45 }
46 /// ensure that current token has given value; return error if it's not a case; get new token
47 void MustBeM ( GenericToken t, const char* message = nullptr )
48 { MustBe ( t, message ); NextLex (); }
49 /// general error message
50 [[noreturn]] void parseError ( const char* p ) const { scan.error(p); }
51
52 public: // interface
53 /// c'tor
54 explicit CommonParser ( std::istream* in ) : scan ( in ) { NextLex (); }
55 /// empty d'tor
56 virtual ~CommonParser() = default;
57 }; // CommonParser
58
59 #endif // _COMMON_PARSER_HPP