From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id BE7E0385E45D; Tue, 16 Jan 2024 18:18:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE7E0385E45D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705429093; bh=vY2bJxuAMHvFE9++DD7Gv1aaE/cXcI7qkW1AuNwOOnk=; h=From:To:Subject:Date:From; b=MtR91HBh8YfHBmdeK3dTMfQovmHqPjY1Cpx1YBWaG8VLPfUnL3Oek7QnIt83svZ0u w5Jmo8AsYlXH9NGgnbgUuhgh0mYfjxzKMTXxtodjbffvdnu6IFvYi+IJ8dDmvLKKu3 3Zb41Yw3Bernv+BcrQzFoxyijjkSV1zKrDX/NwYE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8153] gccrs: Fix float lexing and tuple index disambiguation X-Act-Checkin: gcc X-Git-Author: Pierre-Emmanuel Patry X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 4bd9f1159ba054c9cacfd9a5cd0186c1791987d1 X-Git-Newrev: 348f028fc2957d13e828030119938b8fccb00fc3 Message-Id: <20240116181813.BE7E0385E45D@sourceware.org> Date: Tue, 16 Jan 2024 18:18:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:348f028fc2957d13e828030119938b8fccb00fc3 commit r14-8153-g348f028fc2957d13e828030119938b8fccb00fc3 Author: Pierre-Emmanuel Patry Date: Tue Oct 31 15:23:45 2023 +0100 gccrs: Fix float lexing and tuple index disambiguation When a float has a floating point but no value after it, a zero was added this lead to errors when trying to disambiguate a float into a tuple index. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_decimal_int_or_float): Remove additional zero after empty floating point. * parse/rust-parse-impl.h (Parser::left_denotation): Handle float with empty floating point. Signed-off-by: Pierre-Emmanuel Patry Diff: --- gcc/rust/lex/rust-lex.cc | 3 --- gcc/rust/parse/rust-parse-impl.h | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index b78565ec3a5..107dbad2ff9 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -2351,9 +2351,6 @@ Lexer::parse_decimal_int_or_float (location_t loc) current_char = peek_input (); length++; - // add a '0' after the . to prevent ambiguity - str += '0'; - // type hint not allowed current_column += length; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 0e50c9eb17a..fd648c53e14 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -12892,12 +12892,18 @@ Parser::left_denotation (const_TokenPtr tok, auto dot_pos = str.find ("."); auto prefix = str.substr (0, dot_pos); auto suffix = str.substr (dot_pos + 1); - lexer.split_current_token ( - {Token::make_int (current_loc, std::move (prefix), - CORETYPE_PURE_DECIMAL), - Token::make (DOT, current_loc + 1), - Token::make_int (current_loc + 2, std::move (suffix), - CORETYPE_PURE_DECIMAL)}); + if (dot_pos == str.size () - 1) + lexer.split_current_token ( + {Token::make_int (current_loc, std::move (prefix), + CORETYPE_PURE_DECIMAL), + Token::make (DOT, current_loc + 1)}); + else + lexer.split_current_token ( + {Token::make_int (current_loc, std::move (prefix), + CORETYPE_PURE_DECIMAL), + Token::make (DOT, current_loc + 1), + Token::make_int (current_loc + 2, std::move (suffix), + CORETYPE_PURE_DECIMAL)}); return parse_tuple_index_expr (tok, std::move (left), std::move (outer_attrs), restrictions);