4 * Created on: Aug 26, 2012
8 #include "Interpreter.h"
10 #include "ParsedSource.h"
11 #include "../battle/Monster.h"
13 using battle::Monster;
20 void Interpreter::ReadSource() {
21 for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
22 const Definition &dfn(source.GetDefinition(*i));
23 if (dfn.HasLiteralValue()) {
31 void Interpreter::ReadLiteral(const Definition &dfn) {
32 switch (dfn.GetLiteral()->GetType()) {
33 case Literal::ARRAY_VALUES:
34 throw Error("unhandled literal: array of values");
36 case Literal::ARRAY_PROPS:
37 throw Error("unhandled literal: array of values");
39 case Literal::BOOLEAN:
40 throw Error("unhandled literal: array of values");
43 throw Error("unhandled literal: array of values");
46 throw Error("unhandled literal: array of values");
49 throw Error("unhandled literal: array of values");
52 throw Error("unhandled literal: array of values");
55 throw Error("unhandled literal: array of values");
60 void Interpreter::ReadObject(const Definition &dfn) {
61 if (dfn.TypeName() == "Monster") {
62 monsters.resize(monsters.size() + 1);
63 ReadMonster(monsters.back(), *dfn.GetProperties());
65 throw Error("unhandled object: " + dfn.TypeName());
70 void Interpreter::ReadMonster(Monster &m, const PropertyList &props) {
71 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
72 if (i->first == "name") {
73 if (i->second->IsLiteral()) {
74 m.SetName(i->second->GetLiteral().GetString().c_str());
76 throw Error("identifier resolution not implemented");
79 throw Error("unknown monster property: " + i->first);