]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/ParsedSource.cpp
parse scripts
[l2e.git] / src / loader / ParsedSource.cpp
index e1a1d0aa030e3100e0a831205407e611443fb4aa..6b2fc80413207811b90631c1bfc493982c95c5ee 100644 (file)
@@ -279,6 +279,16 @@ Literal::Literal(const string &typeName, PropertyList *properties)
 
 }
 
+Literal::Literal(const vector<ScriptToken *> &s)
+: props(0)
+, script(s)
+, i1(0), i2(0)
+, i3(0), i4(0)
+, b(false)
+, type(SCRIPT) {
+
+}
+
 Literal::~Literal() {
        switch (type) {
                case ARRAY_VALUES:
@@ -294,6 +304,11 @@ Literal::~Literal() {
                case OBJECT:
                        delete props;
                        break;
+               case SCRIPT:
+                       for (vector<ScriptToken *>::const_iterator i(script.begin()), end(script.end()); i != end; ++i) {
+                               delete *i;
+                       }
+                       break;
                default:
                        break;
        }
@@ -400,6 +415,14 @@ const PropertyList *Literal::GetProperties() const {
        }
 }
 
+const vector<ScriptToken *> &Literal::GetScript() const {
+       if (type == SCRIPT) {
+               return script;
+       } else {
+               throw runtime_error("tried to access script of non-script literal");
+       }
+}
+
 
 Value::~Value() {
        if (isLiteral) {
@@ -423,6 +446,61 @@ const std::string &Value::GetIdentifier() const {
        }
 }
 
+
+ScriptToken::ScriptToken(const string &s, Type t)
+: literal(0)
+, str(s)
+, type(t) {
+       if (type == LITERAL) {
+               throw runtime_error("cannot create script literal without literal");
+       }
+}
+
+ScriptToken::ScriptToken(Literal *l)
+: literal(l)
+, str()
+, type(LITERAL) {
+       if (!literal) {
+               throw runtime_error("cannot create script literal without literal");
+       }
+}
+
+ScriptToken::~ScriptToken() {
+       delete literal;
+}
+
+const string &ScriptToken::RegisterName() const {
+       if (type == REGISTER) {
+               return str;
+       } else {
+               throw runtime_error("access to register name of non-register script token");
+       }
+}
+
+const string &ScriptToken::CommandName() const {
+       if (type == COMMAND) {
+               return str;
+       } else {
+               throw runtime_error("access to command name of non-command script token");
+       }
+}
+
+const string &ScriptToken::GetIdentifier() const {
+       if (type == IDENTIFIER) {
+               return str;
+       } else {
+               throw runtime_error("access to identifier of non-identifier script token");
+       }
+}
+
+const Literal *ScriptToken::GetLiteral() const {
+       if (type == LITERAL) {
+               return literal;
+       } else {
+               throw runtime_error("access to literal value of non-literal script token");
+       }
+}
+
 }
 
 
@@ -477,6 +555,9 @@ ostream &operator <<(ostream &out, const loader::Literal &l) {
                case loader::Literal::OBJECT:
                        out << "object of type " << l.GetTypeName();
                        break;
+               case loader::Literal::SCRIPT:
+                       out << "script";
+                       break;
        }
        return out;
 }