Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
-#include <cctype>
-#include <sstream>
+#include <msp/strings/formatter.h>
#include "binaryparser.h"
#include "parser.h"
#include "statement.h"
Parser::Parser(IO::Base &i, const string &s):
in(i),
+ main_src(s),
src(s),
good(true),
mode(new TextParser(in, src))
delete mode;
mode=new TextParser(in, src);
}
+ else if(st.keyword=="__src")
+ {
+ string s=st.args[0].get<string>();
+ if(s.empty())
+ src=main_src;
+ else
+ src=format("%s[%s]", main_src, s);
+ }
else
return st;
}
using namespace Msp;
Compiler::Compiler(DataFile::Writer &w):
- writer(w)
+ writer(w),
+ reset_src(false)
{
add("file", &Compiler::file);
add("for_each", &Compiler::for_each);
void Compiler::write(const DataFile::Statement &st)
{
+ if(reset_src)
+ {
+ writer.write((DataFile::Statement("__src"), string()));
+ reset_src=false;
+ }
+
for(list<DataFile::Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
writer.write(*i);
}
void Compiler::process_file(const FS::Path &fn, const list<DataFile::Statement> &st)
{
- for(list<DataFile::Statement>::const_iterator i=st.begin(); i!=st.end(); ++i)
+ writer.write((DataFile::Statement("__src"), FS::basename(fn.str())));
+ reset_src=true;
+
+ if(st.empty())
+ process_file(fn);
+ else
{
- if(i->keyword=="_content")
- process_file(fn);
- else
+ for(list<DataFile::Statement>::const_iterator i=st.begin(); i!=st.end(); ++i)
{
- DataFile::Statement s=*i;
- process_statement(fn, s);
- writer.write(s);
+ if(i->keyword=="_content")
+ process_file(fn);
+ else
+ {
+ DataFile::Statement s=*i;
+ process_statement(fn, s);
+ writer.write(s);
+ }
}
}
}
void File::finish()
{
- if(write_st.empty())
- compiler.process_file(filename);
- else
- compiler.process_file(filename, write_st);
+ compiler.process_file(filename, write_st);
}
void File::write(const DataFile::Statement &st)
private:
Msp::DataFile::Writer &writer;
+ bool reset_src;
public:
Compiler(Msp::DataFile::Writer &);
void process_file(const Msp::FS::Path &);
};
+
class File: public Msp::DataFile::Loader
{
private:
void write(const Msp::DataFile::Statement &);
};
+
class ForEach: public Msp::DataFile::Loader
{
private: