]> git.tdb.fi Git - libs/datafile.git/blob - source/parser.h
Use libmspio instead of C++ iostreams
[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 src;
31         bool        good;
32         ParserMode  *mode;
33
34 public:
35         Parser(IO::Base &i, const std::string &s);
36         ~Parser();
37
38         /**
39         Reads a statement from the input.  If the end of input was reached, an empty
40         invalid statement will be returned.  If an error occurs, the parser will be
41         marked as bad and no more statements may be read, even if the exception was
42         caught.
43         */
44         Statement parse();
45
46         operator bool() const { return good && in; }
47 };
48
49 } // namespace DataFile
50 } // namespace Msp
51
52 #endif