]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix float lexing and tuple index disambiguation
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 31 Oct 2023 14:23:45 +0000 (15:23 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:13:15 +0000 (19:13 +0100)
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 <pierre-emmanuel.patry@embecosm.com>
gcc/rust/lex/rust-lex.cc
gcc/rust/parse/rust-parse-impl.h

index b78565ec3a57da271502f436188c665b7fdc36b6..107dbad2ff9f2ceb9162df1302e563fa061afda3 100644 (file)
@@ -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;
index 0e50c9eb17a54f84ad25f04b27cfb9687be5031d..fd648c53e148bacb7cb6ba181580a06e7d79313a 100644 (file)
@@ -12892,12 +12892,18 @@ Parser<ManagedTokenSource>::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);