+/*
+ * Interpreter.cpp
+ *
+ * Created on: Aug 26, 2012
+ * Author: holy
+ */
+
+#include "Interpreter.h"
+
+#include "ParsedSource.h"
+#include "../battle/Monster.h"
+
+using battle::Monster;
+using std::map;
+using std::set;
+using std::string;
+
+namespace loader {
+
+void Interpreter::ReadSource() {
+ for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
+ const Definition &dfn(source.GetDefinition(*i));
+ if (dfn.HasLiteralValue()) {
+ ReadLiteral(dfn);
+ } else {
+ ReadObject(dfn);
+ }
+ }
+}
+
+void Interpreter::ReadLiteral(const Definition &dfn) {
+ switch (dfn.GetLiteral()->GetType()) {
+ case Literal::ARRAY_VALUES:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::ARRAY_PROPS:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::BOOLEAN:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::COLOR:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::NUMBER:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::STRING:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::VECTOR:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::OBJECT:
+ throw Error("unhandled literal: array of values");
+ break;
+ }
+}
+
+void Interpreter::ReadObject(const Definition &dfn) {
+ if (dfn.TypeName() == "Monster") {
+ monsters.resize(monsters.size() + 1);
+ ReadMonster(monsters.back(), *dfn.GetProperties());
+ } else {
+ throw Error("unhandled object: " + dfn.TypeName());
+ }
+}
+
+
+void Interpreter::ReadMonster(Monster &m, const PropertyList &props) {
+ for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+ if (i->first == "name") {
+ if (i->second->IsLiteral()) {
+ m.SetName(i->second->GetLiteral().GetString().c_str());
+ } else {
+ throw Error("identifier resolution not implemented");
+ }
+ } else {
+ throw Error("unknown monster property: " + i->first);
+ }
+ }
+}
+
+}