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