From 66aeadbe43dcb4f95e5bc47f45be6509a983540b Mon Sep 17 00:00:00 2001 From: sof Date: Tue, 14 May 2002 21:08:59 +0000 Subject: [PATCH] [project @ 2002-05-14 21:08:59 by sof] lexNumberBase: support negative exponents --- Text/Read/Lex.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Text/Read/Lex.hs b/Text/Read/Lex.hs index 5442f36..7fdf024 100644 --- a/Text/Read/Lex.hs +++ b/Text/Read/Lex.hs @@ -340,12 +340,21 @@ lexNumberBase base = where value xs mFrac mExp = valueFracExp (val (fromIntegral base) 0 xs) mFrac mExp - valueFracExp a Nothing mExp = Left (valueExp a mExp) + valueFracExp a Nothing mExp + | validIntExp mExp = Left (valueExpInt a mExp) + | otherwise = Right (valueExp (fromIntegral a) mExp) valueFracExp a (Just fs) mExp = Right (valueExp (fromInteger a + frac (fromIntegral base) 0 1 fs) mExp) + -- only positive exponents allowed + validIntExp Nothing = True + validIntExp (Just e) = e >= 0 + + valueExpInt a Nothing = a + valueExpInt a (Just exp) = a * ((fromIntegral base) ^ exp) + valueExp a Nothing = a - valueExp a (Just exp) = a * (fromIntegral base ^ exp) + valueExp a (Just exp) = a * ((fromIntegral base) ^^ exp) lexFrac :: Base -> ReadP (Maybe Digits) lexFrac base = -- 1.7.10.4