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