Skip to content

Commit

Permalink
Fix float lexing and tuple index disambiguation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
P-E-P committed Nov 15, 2023
1 parent 31c5637 commit e79301c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 0 additions & 3 deletions gcc/rust/lex/rust-lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e79301c

Please sign in to comment.