mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibCpp: Support parsing enum classes
This commit is contained in:
parent
5ee753ffaa
commit
c1ee0c1685
Notes:
sideshowbarker
2024-07-18 11:23:38 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/c1ee0c1685d Pull-request: https://github.com/SerenityOS/serenity/pull/8260 Reviewed-by: https://github.com/alimpfard
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -654,7 +654,23 @@ Optional<Parser::DeclarationType> Parser::match_class_member(const StringView& c
|
|||
|
||||
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()
|
||||
|
@ -1026,6 +1042,14 @@ NonnullRefPtr<EnumDeclaration> Parser::parse_enum_declaration(ASTNode& parent)
|
|||
ScopeLogger<CPP_DEBUG> logger;
|
||||
auto enum_decl = create_ast_node<EnumDeclaration>(parent, position(), {});
|
||||
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);
|
||||
enum_decl->m_name = text_of_token(name_token);
|
||||
consume(Token::Type::LeftCurly);
|
||||
|
|
Loading…
Reference in a new issue