1 #ifndef MSP_DATAFILE_PARSER_H_
2 #define MSP_DATAFILE_PARSER_H_
5 #include <msp/core/noncopyable.h>
7 #include "mspdatafile_api.h"
19 Frontend for loading datafiles. Handles switching between text and binary
20 formats. A Parser evaluates into a boolean value indicating whether more
21 statements may be read.
23 class MSPDATAFILE_API Parser: private NonCopyable
30 ParserMode *mode = nullptr;
33 Parser(IO::Base &i, const std::string &s);
36 /** Reads a statement from the input. If the end of input was reached, an
37 empty invalid statement will be returned. If an error occurs, the parser
38 will be marked as bad and no more statements may be read, even if the
39 exception was caught. */
40 Statement parse(bool raw = false);
43 void process_control_statement(const Statement &);
46 /** Returns a key for the next statement, consisting of its keyword and
47 signature. Not supported in all modes. */
48 const StatementKey *peek(unsigned);
50 /** Parses a statement and feeds its arguments to an action. The action
51 must be appropriate for the statement. Use peek() to determine the
52 statement's signature. */
53 bool parse_and_load(unsigned, Loader &, const LoaderAction &);
55 explicit operator bool() const { return good && in; }
58 } // namespace DataFile