diff options
author | Itamar <itamar8910@gmail.com> | 2021-07-03 11:33:01 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-04 17:50:33 +0200 |
commit | 1dfdfcf820d0b94c2f0780e67e1217b12a8dcd9e (patch) | |
tree | 8bcd15abe65066648b2fae36783f5ff1a4b10c76 | |
parent | 55dd56858364e727c3fd16d130271fd4885cfa9c (diff) | |
download | serenity-1dfdfcf820d0b94c2f0780e67e1217b12a8dcd9e.zip |
LibCpp: Fix parsing of ellipsis
Previously the positional information for the node of an ellipsis was
incorrect.
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 4ef1c3ea2b..92fa07e02a 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -743,11 +743,12 @@ Optional<NonnullRefPtrVector<Parameter>> Parser::parse_parameter_list(ASTNode& p NonnullRefPtrVector<Parameter> parameters; while (peek().type() != Token::Type::RightParen && !eof()) { if (match_ellipsis()) { - auto last_dot = consume(); - while (peek().type() == Token::Type::Dot) - last_dot = consume(); - auto param = create_ast_node<Parameter>(parent, position(), last_dot.end(), StringView {}); + auto param = create_ast_node<Parameter>(parent, position(), {}, StringView {}); + consume(Token::Type::Dot); + consume(Token::Type::Dot); + auto last_dot = consume(Token::Type::Dot); param->m_is_ellipsis = true; + param->set_end(last_dot.end()); parameters.append(move(param)); } else { auto type = parse_type(parent); @@ -1305,7 +1306,7 @@ bool Parser::match_ellipsis() { if (m_state.token_index > m_tokens.size() - 3) return false; - return peek().type() == Token::Type::Dot && peek().type() == Token::Type::Dot && peek().type() == Token::Type::Dot; + return peek().type() == Token::Type::Dot && peek(1).type() == Token::Type::Dot && peek(2).type() == Token::Type::Dot; } void Parser::add_tokens_for_preprocessor(Token& replaced_token, Preprocessor::DefinedValue& definition) { |