From: simonmar Date: Mon, 17 Mar 2003 14:51:00 +0000 (+0000) Subject: [project @ 2003-03-17 14:51:00 by simonmar] X-Git-Tag: Approx_11550_changesets_converted~1069 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=1f6eb5538a8f31130c746cd7c441a910e107cddf;p=ghc-hetmet.git [project @ 2003-03-17 14:51:00 by simonmar] Fix for lexing of floating point numbers. '9e2' should be a float. Noticed-by: Ross Paterson. --- diff --git a/ghc/compiler/parser/Lex.lhs b/ghc/compiler/parser/Lex.lhs index 2c78f39..162995f 100644 --- a/ghc/compiler/parser/Lex.lhs +++ b/ghc/compiler/parser/Lex.lhs @@ -826,33 +826,39 @@ lex_num cont exts acc buf = -- files is not that common. (ToDo) case expandWhile# is_digit (incCurrentPos buf') of buf2 -> -- points to first non digit char - - let l = case currentChar# buf2 of - 'E'# -> do_exponent - 'e'# -> do_exponent - _ -> buf2 - - do_exponent - = let buf3 = incCurrentPos buf2 in - case currentChar# buf3 of - '-'# | is_digit (lookAhead# buf3 1#) - -> expandWhile# is_digit (incCurrentPos buf3) - '+'# | is_digit (lookAhead# buf3 1#) - -> expandWhile# is_digit (incCurrentPos buf3) - x | is_digit x -> expandWhile# is_digit buf3 - _ -> buf2 - - v = readRational__ (lexemeToString l) - - in case currentChar# l of -- glasgow exts only - '#'# | glaExtsEnabled exts -> let l' = incCurrentPos l in - case currentChar# l' of - '#'# -> cont (ITprimdouble v) (incCurrentPos l') - _ -> cont (ITprimfloat v) l' - _ -> cont (ITrational v) l - - _ -> after_lexnum cont exts acc' buf' + case currentChar# buf of + 'E'# -> float_exponent cont exts buf2 + 'e'# -> float_exponent cont exts buf2 + _ -> float_done cont exts buf2 + + -- numbers like '9e4' are floats + 'E'# -> float_exponent cont exts buf' + 'e'# -> float_exponent cont exts buf' + _ -> after_lexnum cont exts acc' buf' -- it's an integer +float_exponent cont exts buf2 = + let buf3 = incCurrentPos buf2 + buf4 = case currentChar# buf3 of + '-'# | is_digit (lookAhead# buf3 1#) + -> expandWhile# is_digit (incCurrentPos buf3) + '+'# | is_digit (lookAhead# buf3 1#) + -> expandWhile# is_digit (incCurrentPos buf3) + x | is_digit x -> expandWhile# is_digit buf3 + _ -> buf2 + in + float_done cont exts buf4 + +float_done cont exts buf = + case currentChar# buf of -- glasgow exts only + '#'# | glaExtsEnabled exts -> + let buf' = incCurrentPos buf in + case currentChar# buf' of + '#'# -> cont (ITprimdouble v) (incCurrentPos buf') + _ -> cont (ITprimfloat v) buf' + _ -> cont (ITrational v) buf + where + v = readRational__ (lexemeToString buf) + after_lexnum cont exts i buf = case currentChar# buf of '#'# | glaExtsEnabled exts -> cont (ITprimint i) (incCurrentPos buf)