mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
LibCpp: Handle class access-specifiers in the Parser
We can now handle access-specifier tags (for example 'private:') when parsing class declarations. We currently only consume these tags on move on. We'll need to add some logic that accounts for the access level of symbols down the road.
This commit is contained in:
parent
dcdb0c7035
commit
fd851ec5c9
2 changed files with 19 additions and 0 deletions
|
@ -656,6 +656,7 @@ bool Parser::match_class_declaration()
|
|||
|
||||
if (!match_keyword("struct") && !match_keyword("class"))
|
||||
return false;
|
||||
|
||||
consume(Token::Type::Keyword);
|
||||
|
||||
if (!match(Token::Type::Identifier))
|
||||
|
@ -1439,6 +1440,8 @@ NonnullRefPtrVector<Declaration> Parser::parse_class_members(ASTNode& parent)
|
|||
{
|
||||
NonnullRefPtrVector<Declaration> members;
|
||||
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
||||
if (match_access_specifier())
|
||||
consume_access_specifier(); // FIXME: Do not ignore access specifiers
|
||||
auto member_type = match_class_member();
|
||||
if (member_type.has_value()) {
|
||||
members.append(parse_declaration(parent, member_type.value()));
|
||||
|
@ -1450,4 +1453,18 @@ NonnullRefPtrVector<Declaration> Parser::parse_class_members(ASTNode& parent)
|
|||
return members;
|
||||
}
|
||||
|
||||
bool Parser::match_access_specifier()
|
||||
{
|
||||
if (peek(1).type() != Token::Type::Colon)
|
||||
return false;
|
||||
|
||||
return match_keyword("private") || match_keyword("protected") || match_keyword("public");
|
||||
}
|
||||
|
||||
void Parser::consume_access_specifier()
|
||||
{
|
||||
consume(Token::Type::Keyword);
|
||||
consume(Token::Type::Colon);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue