]> git.tdb.fi Git - libs/datafile.git/blob - source/parser.h
c830c3c8367f5c082788ad864f23eed84266439a
[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 <istream>
12 #include <string>
13 #include "input.h"
14
15 namespace Msp {
16 namespace DataFile {
17
18 class ParserMode;
19 class Statement;
20 struct Token;
21
22 /**
23 Frontend for loading datafiles.  Handles switching between text and binary
24 formats.  A Parser evaluates into a boolean value indicating whether more
25 statements may be read.
26 */
27 class Parser
28 {
29 private:
30         Input       in;
31         std::string src;
32         bool        good;
33         ParserMode  *mode;
34
35 public:
36         Parser(std::istream &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