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 {
}
}
+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;
}