Skip to content

Commit

Permalink
Don't emit warnings when parsing floats
Browse files Browse the repository at this point in the history
`Parser::CurrentRuby.parse("9.9999e999")`
> Float 9.9999e999 out of range
  • Loading branch information
Earlopain committed May 17, 2024
1 parent bd672bd commit cb220cd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/parser/lexer.rl
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,23 @@ class Parser::Lexer
@emit_integer_if = lambda { |chars, p| emit(:tINTEGER, chars, @ts, @te - 2); p - 2 }
@emit_integer_rescue = lambda { |chars, p| emit(:tINTEGER, chars, @ts, @te - 6); p - 6 }

@emit_float = lambda { |chars, p| emit(:tFLOAT, Float(chars)); p }
@emit_imaginary_float = lambda { |chars, p| emit(:tIMAGINARY, Complex(0, Float(chars))); p }
@emit_float_if = lambda { |chars, p| emit(:tFLOAT, Float(chars), @ts, @te - 2); p - 2 }
@emit_float_rescue = lambda { |chars, p| emit(:tFLOAT, Float(chars), @ts, @te - 6); p - 6 }
@emit_float = lambda { |chars, p| emit(:tFLOAT, construct_float(chars)); p }
@emit_imaginary_float = lambda { |chars, p| emit(:tIMAGINARY, Complex(0, construct_float(chars))); p }
@emit_float_if = lambda { |chars, p| emit(:tFLOAT, construct_float(chars), @ts, @te - 2); p - 2 }
@emit_float_rescue = lambda { |chars, p| emit(:tFLOAT, construct_float(chars), @ts, @te - 6); p - 6 }

reset
end

def construct_float(chars)
begin
old_verbose, $VERBOSE = $VERBOSE, nil
Float(chars)
ensure
$VERBOSE = old_verbose
end
end

def reset(reset_state=true)
# Ragel state:
if reset_state
Expand Down

0 comments on commit cb220cd

Please sign in to comment.