]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Parser.cpp
lousy implementation of "array of identifiers" type
[l2e.git] / src / loader / Parser.cpp
index 9ddae34c5bdd4b2ac2a688c6765c925c05013917..3f5f3446955ab8d78005912ad1d31df432c658e8 100644 (file)
@@ -1,10 +1,3 @@
-/*
- * Parser.cpp
- *
- *  Created on: Aug 26, 2012
- *      Author: holy
- */
-
 #include "Parser.h"
 
 #include "utility.h"
@@ -266,17 +259,33 @@ Literal *Parser::ParseArray() {
        Token probe(GetToken());
 
        if (probe.type == Token::TYPE_NAME) {
-               vector<PropertyList *> values;
-               while (t.type != Token::BRACKET_CLOSE) {
-                       PropertyList *value(ParsePropertyList());
-                       values.push_back(value);
+               t = GetToken();
+               tok.Putback(t);
+               if (t.type == Token::ANGLE_BRACKET_OPEN) {
+                       vector<PropertyList *> values;
+                       while (t.type != Token::BRACKET_CLOSE) {
+                               PropertyList *value(ParsePropertyList());
+                               values.push_back(value);
 
-                       t = GetToken();
-                       if (t.type != Token::BRACKET_CLOSE && t.type != Token::COMMA) {
-                               throw Error(file, tok.Line(), string("unexpected token ") + TokenTypeToString(t.type) + ", expected , or ]");
+                               t = GetToken();
+                               if (t.type != Token::BRACKET_CLOSE && t.type != Token::COMMA) {
+                                       throw Error(file, tok.Line(), string("unexpected token ") + TokenTypeToString(t.type) + ", expected , or ]");
+                               }
                        }
+                       return new Literal(probe.str, values);
+               } else {
+                       vector<string> values;
+                       while (t.type != Token::BRACKET_CLOSE) {
+                               string value(ParseIdentifier());
+                               values.push_back(value);
+
+                               t = GetToken();
+                               if (t.type != Token::BRACKET_CLOSE && t.type != Token::COMMA) {
+                                       throw Error(file, tok.Line(), string("unexpected token ") + TokenTypeToString(t.type) + ", expected , or ]");
+                               }
+                       }
+                       return new Literal(probe.str, values);
                }
-               return new Literal(probe.str, values);
        } else {
                tok.Putback(probe);
 
@@ -371,7 +380,13 @@ Literal *Parser::ParseScript() {
                                                break;
                                        }
                                        case Token::IDENTIFIER: {
-                                               script.push_back(new ScriptToken(t.str, ScriptToken::IDENTIFIER));
+                                               Token t2(GetToken());
+                                               if (t2.type == Token::COLON) {
+                                                       script.push_back(new ScriptToken(t.str, ScriptToken::LABEL));
+                                               } else {
+                                                       tok.Putback(t2);
+                                                       script.push_back(new ScriptToken(t.str, ScriptToken::IDENTIFIER));
+                                               }
                                                break;
                                        }
                                        case Token::REGISTER: {