]> git.tdb.fi Git - libs/datafile.git/blob - source/parser.h
Remove the loaded flag from PackSource 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 Loader;
11 class LoaderAction;
12 class ParserMode;
13 class Statement;
14 struct StatementKey;
15
16 /**
17 Frontend for loading datafiles.  Handles switching between text and binary
18 formats.  A Parser evaluates into a boolean value indicating whether more
19 statements may be read.
20 */
21 class Parser
22 {
23 private:
24         Input in;
25         std::string main_src;
26         std::string src;
27         bool good;
28         ParserMode *mode;
29
30 public:
31         Parser(IO::Base &i, const std::string &s);
32         ~Parser();
33
34         /** Reads a statement from the input.  If the end of input was reached, an
35         empty invalid statement will be returned.  If an error occurs, the parser
36         will be marked as bad and no more statements may be read, even if the
37         exception was caught. */
38         Statement parse(bool raw = false);
39
40 private:
41         void process_control_statement(const Statement &);
42
43 public:
44         /** Returns a key for the next statement, consisting of its keyword and
45         signature.  Not supported in all modes. */
46         const StatementKey *peek(unsigned);
47
48         /** Parses a statement and feeds its arguments to an action.  The action
49         must be appropriate for the statement.  Use peek() to determine the
50         statement's signature. */
51         bool parse_and_load(unsigned, Loader &, const LoaderAction &);
52
53         operator bool() const { return good && in; }
54 };
55
56 } // namespace DataFile
57 } // namespace Msp
58
59 #endif