mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:07:35 +00:00
LibCpp: Support parsing enum classes
This commit is contained in:
parent
5ee753ffaa
commit
c1ee0c1685
2 changed files with 31 additions and 1 deletions
|
@ -505,6 +505,12 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class Type {
|
||||||
|
RegularEnum,
|
||||||
|
EnumClass
|
||||||
|
};
|
||||||
|
|
||||||
|
Type type { Type::RegularEnum };
|
||||||
Vector<StringView> m_entries;
|
Vector<StringView> m_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -654,7 +654,23 @@ Optional<Parser::DeclarationType> Parser::match_class_member(const StringView& c
|
||||||
|
|
||||||
bool Parser::match_enum_declaration()
|
bool Parser::match_enum_declaration()
|
||||||
{
|
{
|
||||||
return match_keyword("enum");
|
save_state();
|
||||||
|
ScopeGuard state_guard = [this] { load_state(); };
|
||||||
|
|
||||||
|
if (!match_keyword("enum"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
consume(Token::Type::Keyword);
|
||||||
|
|
||||||
|
if (match_keyword("class"))
|
||||||
|
consume(Token::Type::Keyword);
|
||||||
|
|
||||||
|
if (!match(Token::Type::Identifier))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
consume(Token::Type::Identifier);
|
||||||
|
|
||||||
|
return match(Token::Type::LeftCurly);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Parser::match_class_declaration()
|
bool Parser::match_class_declaration()
|
||||||
|
@ -1026,6 +1042,14 @@ NonnullRefPtr<EnumDeclaration> Parser::parse_enum_declaration(ASTNode& parent)
|
||||||
ScopeLogger<CPP_DEBUG> logger;
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto enum_decl = create_ast_node<EnumDeclaration>(parent, position(), {});
|
auto enum_decl = create_ast_node<EnumDeclaration>(parent, position(), {});
|
||||||
consume_keyword("enum");
|
consume_keyword("enum");
|
||||||
|
|
||||||
|
if (match_keyword("class")) {
|
||||||
|
consume(Token::Type::Keyword);
|
||||||
|
enum_decl->type = EnumDeclaration::Type::EnumClass;
|
||||||
|
} else {
|
||||||
|
enum_decl->type = EnumDeclaration::Type::RegularEnum;
|
||||||
|
}
|
||||||
|
|
||||||
auto name_token = consume(Token::Type::Identifier);
|
auto name_token = consume(Token::Type::Identifier);
|
||||||
enum_decl->m_name = text_of_token(name_token);
|
enum_decl->m_name = text_of_token(name_token);
|
||||||
consume(Token::Type::LeftCurly);
|
consume(Token::Type::LeftCurly);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue