diff options
author | Itamar <itamar8910@gmail.com> | 2021-05-15 09:44:31 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-15 23:28:50 +0200 |
commit | 0e51aea78140c99aacbec5c0fbaddb01c8c2a622 (patch) | |
tree | 356372eca75f8be27600c5f2890e0fe0389641a1 /Userland/Libraries/LibCpp | |
parent | 9408013177cdff03610a12b33ce90d5055f54988 (diff) | |
download | serenity-0e51aea78140c99aacbec5c0fbaddb01c8c2a622.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibCpp')
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 9619abab04..62ae77e2a3 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -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); |