From: Daniel Karbach Date: Tue, 11 Sep 2012 18:34:29 +0000 (+0200) Subject: revised array type notation X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=40233fc8eea1c80e6c57a004dfe7e55dabf06edb;p=l2e.git revised array type notation --- diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index c0d3a41..e1a1d0a 100644 --- a/src/loader/ParsedSource.cpp +++ b/src/loader/ParsedSource.cpp @@ -191,11 +191,14 @@ Literal::Literal(const vector &v) , i3(0), i4(0) , b(false) , type(ARRAY_VALUES) { - + if (!v.empty()) { + typeName = v.front()->GetLiteral().GetTypeName(); + } } -Literal::Literal(const std::vector &pls) +Literal::Literal(const string &typeName, const vector &pls) : props(0) +, typeName(typeName) , propertyLists(pls) , i1(0), i2(0) , i3(0), i4(0) @@ -206,6 +209,7 @@ Literal::Literal(const std::vector &pls) Literal::Literal(bool b) : props(0) +, typeName("Boolean") , i1(0), i2(0) , i3(0), i4(0) , b(b) @@ -215,6 +219,7 @@ Literal::Literal(bool b) Literal::Literal(int r, int g, int b, int a) : props(0) +, typeName("Color") , i1(r), i2(g) , i3(b), i4(a) , b(false) @@ -224,6 +229,7 @@ Literal::Literal(int r, int g, int b, int a) Literal::Literal(int number) : props(0) +, typeName("Number") , i1(number), i2(0) , i3(0), i4(0) , b(false) @@ -233,6 +239,7 @@ Literal::Literal(int number) Literal::Literal(const string &dir, const string &path) : props(0) +, typeName("Path") , str(CatPath(dir, path)) , i1(0), i2(0) , i3(0), i4(0) @@ -243,6 +250,7 @@ Literal::Literal(const string &dir, const string &path) Literal::Literal(const string &str) : props(0) +, typeName("String") , str(str) , i1(0), i2(0) , i3(0), i4(0) @@ -253,6 +261,7 @@ Literal::Literal(const string &str) Literal::Literal(int x, int y) : props(0) +, typeName("Vector") , i1(x), i2(y) , i3(0), i4(0) , b(false) @@ -262,7 +271,7 @@ Literal::Literal(int x, int y) Literal::Literal(const string &typeName, PropertyList *properties) : props(properties) -, str(typeName) +, typeName(typeName) , i1(0), i2(0) , i3(0), i4(0) , b(false) @@ -380,11 +389,7 @@ int Literal::GetY() const { } const string &Literal::GetTypeName() const { - if (type == OBJECT) { - return str; - } else { - throw runtime_error("tried to access type name of non-object literal"); - } + return typeName; } const PropertyList *Literal::GetProperties() const { diff --git a/src/loader/ParsedSource.h b/src/loader/ParsedSource.h index e10b287..5012729 100644 --- a/src/loader/ParsedSource.h +++ b/src/loader/ParsedSource.h @@ -36,7 +36,7 @@ public: public: explicit Literal(const std::vector &); - explicit Literal(const std::vector &); + Literal(const std::string &, const std::vector &); explicit Literal(bool); Literal(int r, int g, int b, int a = 255); explicit Literal(int number); @@ -71,7 +71,7 @@ public: private: PropertyList *props; - std::string str; + std::string typeName, str; std::vector values; std::vector propertyLists; int i1, i2, i3, i4; diff --git a/src/loader/Parser.cpp b/src/loader/Parser.cpp index aa770ff..183accb 100644 --- a/src/loader/Parser.cpp +++ b/src/loader/Parser.cpp @@ -254,9 +254,8 @@ Literal *Parser::ParseArray() { AssertTokenType(t.type, Tokenizer::Token::BRACKET_OPEN); Tokenizer::Token probe(GetToken()); - tok.Putback(probe); - if (probe.type == Tokenizer::Token::ANGLE_BRACKET_OPEN) { + if (probe.type == Tokenizer::Token::TYPE_NAME) { vector values; while (t.type != Tokenizer::Token::BRACKET_CLOSE) { PropertyList *value(ParsePropertyList()); @@ -267,8 +266,10 @@ Literal *Parser::ParseArray() { throw Error(file, tok.Line(), string("unexpected token ") + TokenTypeToString(t.type) + ", expected , or ]"); } } - return new Literal(values); + return new Literal(probe.str, values); } else { + tok.Putback(probe); + vector values; while (t.type != Tokenizer::Token::BRACKET_CLOSE) { Value *value(ParseValue()); diff --git a/test-data/test.l2s b/test-data/test.l2s index 48817f4..b2fc8b6 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -48,7 +48,8 @@ export Monster lizard { sprite: lizardSprite, frametime: fourFramesTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 0, row: 1, disposition: < 0, 16> }, { column: 0, row: 0, disposition: < 0, 16> }, { column: 0, row: 1, disposition: < 0, 16> }, @@ -91,7 +92,8 @@ export Hero maxim { sprite: maximSprite, frametime: frameTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 1, row: 0, disposition: < 0, 0> }, { column: 1, row: 0, disposition: < 0, 0> }, { column: 1, row: 0, disposition: < 0, 0> }, @@ -125,7 +127,8 @@ export Hero maxim { sprite: maximSprite, frametime: fiveFramesTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 3, row: 0, disposition: < 0, 0> }, { column: 3, row: 0, disposition: < 0, 0> }, { column: 3, row: 1, disposition: < 0, 0> } @@ -167,7 +170,8 @@ export Hero selan { sprite: selanSprite, frametime: frameTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 1, row: 0, disposition: < 4, 0> }, { column: 1, row: 0, disposition: < 4, 0> }, { column: 1, row: 0, disposition: < 8, 2> }, @@ -188,7 +192,8 @@ export Hero selan { sprite: selanSprite, frametime: frameTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 3, row: 0, disposition: < 0, 0> }, { column: 3, row: 0, disposition: < 0, 0> }, { column: 3, row: 0, disposition: < 0, 0> }, @@ -237,7 +242,8 @@ export Hero guy { sprite: guySprite, frametime: frameTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 1, row: 0, disposition: <-4, 0> }, { column: 1, row: 0, disposition: <-4, 0> }, { column: 1, row: 0, disposition: <-8, 0> }, @@ -290,7 +296,8 @@ export Hero dekar { sprite: dekarSprite, frametime: frameTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 1, row: 0, disposition: < 4, 0> }, { column: 1, row: 0, disposition: < 8, 2> }, { column: 2, row: 0, disposition: <12, 4> }, @@ -311,7 +318,8 @@ export Hero dekar { sprite: dekarSprite, frametime: twoFramesTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 3, row: 0, disposition: < 0, 0> }, { column: 3, row: 0, disposition: < 0, 0> }, { column: 3, row: 0, disposition: < 0, 0> }, @@ -389,7 +397,8 @@ export BattleResources battleResources { numberAnimationPrototype: ComplexAnimation { frametime: frameTime, repeat: false, - frames: [ + frames: + [ ComplexAnimationFrame { column: 0, row: 0, disposition: < 0, 0> }, { column: 0, row: 0, disposition: < 0,-26> }, { column: 0, row: 0, disposition: < 0,-42> },