From d9f5a974cb6c09b7e20eb5ca7e7af0fb0b4c661b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 14 Nov 2020 15:06:27 +0100 Subject: [PATCH] Remove requirement for a comma after the last enum entry --- source/parser/parser.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/parser/parser.cpp b/source/parser/parser.cpp index 7e0f28736..4695ed54e 100644 --- a/source/parser/parser.cpp +++ b/source/parser/parser.cpp @@ -88,17 +88,24 @@ namespace hex::lang { auto enumNode = new ASTNodeEnum(underlyingType, enumName); while (!tryConsume(curr, {Token::Type::ScopeClose})) { - if (tryConsume(curr, { Token::Type::Identifier, Token::Type::Separator})) { + if (tryConsume(curr, { Token::Type::Identifier, Token::Type::Separator }) || tryConsume(curr, { Token::Type::Identifier, Token::Type::ScopeClose })) { u64 value; if (enumNode->getValues().empty()) value = 0; else value = enumNode->getValues().back().first + 1; - enumNode->getValues().push_back({ value, curr[-2].identifierToken.identifier }); + enumNode->getValues().emplace_back(value, curr[-2].identifierToken.identifier); + + if (curr[-1].type == Token::Type::ScopeClose) + break; } else if (tryConsume(curr, { Token::Type::Identifier, Token::Type::Operator, Token::Type::Integer, Token::Type::Separator})) { - enumNode->getValues().push_back({ curr[-2].integerToken.integer, curr[-4].identifierToken.identifier }); + enumNode->getValues().emplace_back(curr[-2].integerToken.integer, curr[-4].identifierToken.identifier); + } + else if (tryConsume(curr, { Token::Type::Identifier, Token::Type::Operator, Token::Type::Integer, Token::Type::ScopeClose})) { + enumNode->getValues().emplace_back(curr[-2].integerToken.integer, curr[-4].identifierToken.identifier); + break; } else { delete enumNode;