1 #include <msp/strings/format.h>
2 #include "binaryparser.h"
6 #include "textparser.h"
13 Parser::Parser(IO::Base &i, const string &s):
18 mode(new TextParser(in, src))
26 Statement Parser::parse(bool raw)
29 throw logic_error("Parser::parse() !good");
35 Statement st = mode->parse();
36 if(!st.keyword.compare(0, 2, "__"))
39 process_control_statement(st);
42 if(raw || !st.control)
44 else if(!good) // This will occur with an __end statement
48 catch(const exception &e)
51 if(dynamic_cast<const data_error *>(&e))
54 throw data_error(src, in.get_line_number(), e);
58 void Parser::process_control_statement(const Statement &st)
60 if(st.keyword=="__bin")
63 mode = new BinaryParser(in, src);
65 else if(st.keyword=="__text")
68 mode = new TextParser(in, src);
70 else if(st.keyword=="__z")
72 else if(st.keyword=="__src")
74 string s = st.args[0].get<string>();
78 src = format("%s[%s]", main_src, s);
80 else if(st.keyword=="__end")
83 mode->process_control_statement(st);
86 } // namespace DataFile