From: Daniel Karbach Date: Sun, 26 Aug 2012 19:54:48 +0000 (+0200) Subject: added support for arrays of property lists X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=4b3deb01b66307f5025938538d27e6ad86cfea13;p=l2e.git added support for arrays of property lists --- diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index 75d7efb..9d0f597 100644 --- a/src/loader/ParsedSource.cpp +++ b/src/loader/ParsedSource.cpp @@ -98,7 +98,17 @@ Literal::Literal(const vector &v) , i1(0), i2(0) , i3(0), i4(0) , b(false) -, type(ARRAY) { +, type(ARRAY_VALUES) { + +} + +Literal::Literal(const std::vector &pls) +: props(0) +, propertyLists(pls) +, i1(0), i2(0) +, i3(0), i4(0) +, b(false) +, type(ARRAY_PROPS) { } diff --git a/src/loader/ParsedSource.h b/src/loader/ParsedSource.h index ebcc853..f78a49e 100644 --- a/src/loader/ParsedSource.h +++ b/src/loader/ParsedSource.h @@ -22,7 +22,8 @@ class Value; class Literal { enum Type { - ARRAY, + ARRAY_VALUES, + ARRAY_PROPS, BOOLEAN, COLOR, NUMBER, @@ -33,6 +34,7 @@ class Literal { public: explicit Literal(const std::vector &); + explicit Literal(const std::vector &); explicit Literal(bool); Literal(int r, int g, int b, int a = 255); Literal(const std::string &); @@ -43,6 +45,7 @@ private: PropertyList *props; std::string str; std::vector values; + std::vector propertyLists; int i1, i2, i3, i4; bool b; Type type; diff --git a/src/loader/Parser.cpp b/src/loader/Parser.cpp index 39f0f87..68fb326 100644 --- a/src/loader/Parser.cpp +++ b/src/loader/Parser.cpp @@ -216,19 +216,34 @@ Literal *Parser::ParseArray() { Tokenizer::Token t(GetToken()); AssertTokenType(t.type, Tokenizer::Token::BRACKET_OPEN); - vector values; - - while (t.type != Tokenizer::Token::ANGLE_BRACKET_CLOSE) { - Value *value(ParseValue()); - values.push_back(value); - - t = GetToken(); - if (t.type != Tokenizer::Token::BRACKET_CLOSE && t.type != Tokenizer::Token::COMMA) { - throw Error(file, tok.Line(), string("unexpected token ") + TokenTypeToString(t.type) + ", expected , or ]"); + Tokenizer::Token probe(GetToken()); + tok.Putback(probe); + + if (probe.type == Tokenizer::Token::ANGLE_BRACKET_OPEN) { + vector values; + while (t.type != Tokenizer::Token::BRACKET_CLOSE) { + PropertyList *value(ParsePropertyList()); + values.push_back(value); + + t = GetToken(); + if (t.type != Tokenizer::Token::BRACKET_CLOSE && t.type != Tokenizer::Token::COMMA) { + throw Error(file, tok.Line(), string("unexpected token ") + TokenTypeToString(t.type) + ", expected , or ]"); + } } + return new Literal(values); + } else { + vector values; + while (t.type != Tokenizer::Token::BRACKET_CLOSE) { + Value *value(ParseValue()); + values.push_back(value); + + t = GetToken(); + if (t.type != Tokenizer::Token::BRACKET_CLOSE && t.type != Tokenizer::Token::COMMA) { + throw Error(file, tok.Line(), string("unexpected token ") + TokenTypeToString(t.type) + ", expected , or ]"); + } + } + return new Literal(values); } - - return new Literal(values); } Literal *Parser::ParseColor() {