]> git.tdb.fi Git - libs/datafile.git/blob - source/parser.h
Restructure the tool and make it able to handle multiple input files
[libs/datafile.git] / source / parser.h
1 #ifndef MSP_DATAFILE_PARSER_H_
2 #define MSP_DATAFILE_PARSER_H_
3
4 #include <string>
5 #include "input.h"
6
7 namespace Msp {
8 namespace DataFile {
9
10 class ParserMode;
11 class Statement;
12 struct Token;
13
14 /**
15 Frontend for loading datafiles.  Handles switching between text and binary
16 formats.  A Parser evaluates into a boolean value indicating whether more
17 statements may be read.
18 */
19 class Parser
20 {
21 private:
22         Input in;
23         std::string main_src;
24         std::string src;
25         bool good;
26         ParserMode *mode;
27
28 public:
29         Parser(IO::Base &i, const std::string &s);
30         ~Parser();
31
32         /**
33         Reads a statement from the input.  If the end of input was reached, an empty
34         invalid statement will be returned.  If an error occurs, the parser will be
35         marked as bad and no more statements may be read, even if the exception was
36         caught.
37         */
38         Statement parse();
39
40         operator bool() const { return good && in; }
41 };
42
43 } // namespace DataFile
44 } // namespace Msp
45
46 #endif