From: Daniel Karbach Date: Sun, 2 Sep 2012 17:19:02 +0000 (+0200) Subject: fixed some issues with the grammar X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=622b633b3c284b3b44c8cbb71528d20b97fe8d59;p=l2e.git fixed some issues with the grammar --- diff --git a/src/loader/Parser.cpp b/src/loader/Parser.cpp index 01ddbe2..aa770ff 100644 --- a/src/loader/Parser.cpp +++ b/src/loader/Parser.cpp @@ -85,23 +85,24 @@ Declaration *Parser::ProbeDefinition() { string typeName(ParseTypeName()); string identifier(ParseIdentifier()); - Tokenizer::Token t(GetToken()); - tok.Putback(t); - if (BeginOfPropertyList(t)) { - auto_ptr propertyList(ParsePropertyList()); - auto_ptr dfn(new Definition(typeName, identifier)); - dfn->SetValue(propertyList.release()); - product.AddDefinition(dfn.get()); - return dfn.release(); - } else if (BeginningOfLiteral(t)) { - auto_ptr literal(ParseLiteral()); - auto_ptr dfn(new Definition(typeName, identifier)); - dfn->SetValue(literal.release()); - product.AddDefinition(dfn.get()); - return dfn.release(); - } else { - return new Declaration(typeName, identifier); + if (tok.HasMore()) { + Tokenizer::Token t(GetToken()); + tok.Putback(t); + if (BeginOfPropertyList(t)) { + auto_ptr propertyList(ParsePropertyList()); + auto_ptr dfn(new Definition(typeName, identifier)); + dfn->SetValue(propertyList.release()); + product.AddDefinition(dfn.get()); + return dfn.release(); + } else if (BeginningOfPrimitiveLiteral(t)) { + auto_ptr literal(ParseLiteral()); + auto_ptr dfn(new Definition(typeName, identifier)); + dfn->SetValue(literal.release()); + product.AddDefinition(dfn.get()); + return dfn.release(); + } } + return new Declaration(typeName, identifier); } bool Parser::BeginningOfLiteral(const Tokenizer::Token &t) const { @@ -121,6 +122,22 @@ bool Parser::BeginningOfLiteral(const Tokenizer::Token &t) const { } } +bool Parser::BeginningOfPrimitiveLiteral(const Tokenizer::Token &t) const { + switch (t.type) { + case Tokenizer::Token::CHEVRON_OPEN: + case Tokenizer::Token::COLON: + case Tokenizer::Token::BRACKET_OPEN: + case Tokenizer::Token::PARENTHESIS_OPEN: + case Tokenizer::Token::NUMBER: + case Tokenizer::Token::STRING: + case Tokenizer::Token::KEYWORD_FALSE: + case Tokenizer::Token::KEYWORD_TRUE: + return true; + default: + return false; + } +} + bool Parser::BeginOfPropertyList(const Tokenizer::Token &t) const { return t.type == Tokenizer::Token::ANGLE_BRACKET_OPEN; } diff --git a/src/loader/Parser.h b/src/loader/Parser.h index ebfeafa..fd8f2cf 100644 --- a/src/loader/Parser.h +++ b/src/loader/Parser.h @@ -71,6 +71,7 @@ private: void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected); void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected, const std::string &msg); bool BeginningOfLiteral(const Tokenizer::Token &) const; + bool BeginningOfPrimitiveLiteral(const Tokenizer::Token &) const; bool BeginOfPropertyList(const Tokenizer::Token &) const; private: