]> git.tdb.fi Git - libs/datafile.git/blob - source/parser.h
Restructure control statement processing
[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
13 /**
14 Frontend for loading datafiles.  Handles switching between text and binary
15 formats.  A Parser evaluates into a boolean value indicating whether more
16 statements may be read.
17 */
18 class Parser
19 {
20 private:
21         Input in;
22         std::string main_src;
23         std::string src;
24         bool good;
25         ParserMode *mode;
26
27 public:
28         Parser(IO::Base &i, const std::string &s);
29         ~Parser();
30
31         /**
32         Reads a statement from the input.  If the end of input was reached, an empty
33         invalid statement will be returned.  If an error occurs, the parser will be
34         marked as bad and no more statements may be read, even if the exception was
35         caught.
36         */
37         Statement parse(bool raw = false);
38
39 private:
40         void process_control_statement(const Statement &);
41
42 public:
43         operator bool() const { return good && in; }
44 };
45
46 } // namespace DataFile
47 } // namespace Msp
48
49 #endif