mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
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:
parent
9408013177
commit
0e51aea781
Notes:
sideshowbarker
2024-07-18 18:04:53 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/0e51aea7814 Pull-request: https://github.com/SerenityOS/serenity/pull/7153
1 changed files with 9 additions and 7 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue