]> git.localhorst.tv Git - l2e.git/commitdiff
fixed some issues with the grammar
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 2 Sep 2012 17:19:02 +0000 (19:19 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 2 Sep 2012 17:19:02 +0000 (19:19 +0200)
src/loader/Parser.cpp
src/loader/Parser.h

index 01ddbe2bbdd19670bee0bcd0f88244063497d542..aa770ff12a55fa1137a1a76511a3246a9d6a73e9 100644 (file)
@@ -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> propertyList(ParsePropertyList());
-               auto_ptr<Definition> dfn(new Definition(typeName, identifier));
-               dfn->SetValue(propertyList.release());
-               product.AddDefinition(dfn.get());
-               return dfn.release();
-       } else if (BeginningOfLiteral(t)) {
-               auto_ptr<Literal> literal(ParseLiteral());
-               auto_ptr<Definition> 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> propertyList(ParsePropertyList());
+                       auto_ptr<Definition> dfn(new Definition(typeName, identifier));
+                       dfn->SetValue(propertyList.release());
+                       product.AddDefinition(dfn.get());
+                       return dfn.release();
+               } else if (BeginningOfPrimitiveLiteral(t)) {
+                       auto_ptr<Literal> literal(ParseLiteral());
+                       auto_ptr<Definition> 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;
 }
index ebfeafaacf0f9c081a0c60512818647ff0311350..fd8f2cfad52fd3d536fc1b013268d60e72de4f1d 100644 (file)
@@ -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: