LibCpp: Modify parsing of a Name's scope

A Name node can now have a non-empty scope and a null name.

For example, "AK::" has a non-empty scope and a null name component.
This commit is contained in:
Itamar 2021-05-15 09:44:31 +03:00 committed by Andreas Kling
parent 9408013177
commit 0e51aea781
Notes: sideshowbarker 2024-07-18 18:04:53 +09:00

View file

@ -1291,17 +1291,19 @@ bool Parser::match_name()
NonnullRefPtr<Name> Parser::parse_name(ASTNode& parent)
{
NonnullRefPtr<Name> name_node = create_ast_node<Name>(parent, position(), {});
while (!eof() && (peek().type() == Token::Type::Identifier || peek().type() == Token::Type::KnownType)) {
while (!eof() && (peek().type() == Token::Type::Identifier || peek().type() == Token::Type::KnownType) && peek(1).type() == Token::Type::ColonColon) {
auto token = consume();
name_node->m_scope.append(create_ast_node<Identifier>(*name_node, token.start(), token.end(), token.text()));
if (peek().type() == Token::Type::ColonColon)
consume();
else
break;
consume(Token::Type::ColonColon);
}
VERIFY(!name_node->m_scope.is_empty());
name_node->m_name = name_node->m_scope.take_last();
if (peek().type() == Token::Type::Identifier || peek().type() == Token::Type::KnownType) {
auto token = consume();
name_node->m_name = create_ast_node<Identifier>(*name_node, token.start(), token.end(), token.text());
} else {
name_node->set_end(position());
return name_node;
}
if (match_template_arguments()) {
consume(Token::Type::Less);