summaryrefslogtreecommitdiff
path: root/compiler/parser/Lexer.x
diff options
context:
space:
mode:
authorNolan <nolane16@gmail.com>2017-05-08 17:46:22 -0400
committerBen Gamari <ben@smart-cactus.org>2017-05-08 17:46:24 -0400
commit0279b745c29213c479b61f864ca5d3d2ae76ac77 (patch)
tree6f5fb39ddcdb142f017e9196ddc480971eb661ae /compiler/parser/Lexer.x
parentdc3b4af6d0c38ced4f0becf575474a1c1b08f794 (diff)
downloadhaskell-0279b745c29213c479b61f864ca5d3d2ae76ac77.tar.gz
Make XNegativeLiterals treat -0.0 as negative 0
Reviewers: austin, goldfire, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, mpickering GHC Trac Issues: #13211 Differential Revision: https://phabricator.haskell.org/D3543
Diffstat (limited to 'compiler/parser/Lexer.x')
-rw-r--r--compiler/parser/Lexer.x29
1 files changed, 19 insertions, 10 deletions
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 4c86688ea9..6ebd0877e7 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -114,7 +114,8 @@ import DynFlags
-- compiler/basicTypes
import SrcLoc
import Module
-import BasicTypes ( InlineSpec(..), RuleMatchInfo(..), FractionalLit(..),
+import BasicTypes ( InlineSpec(..), RuleMatchInfo(..),
+ IntegralLit(..), FractionalLit(..),
SourceText(..) )
-- compiler/parser
@@ -707,7 +708,7 @@ data Token
| ITchar SourceText Char -- Note [Literal source text] in BasicTypes
| ITstring SourceText FastString -- Note [Literal source text] in BasicTypes
- | ITinteger SourceText Integer -- Note [Literal source text] in BasicTypes
+ | ITinteger IntegralLit -- Note [Literal source text] in BasicTypes
| ITrational FractionalLit
| ITprimchar SourceText Char -- Note [Literal source text] in BasicTypes
@@ -1276,15 +1277,21 @@ tok_integral itint transint transbuf translen (radix,char_to_int) span buf len
$! transint $ parseUnsignedInteger
(offsetBytes transbuf buf) (subtract translen len) radix char_to_int
--- some conveniences for use with tok_integral
tok_num :: (Integer -> Integer)
- -> Int -> Int
- -> (Integer, (Char->Int)) -> Action
-tok_num = tok_integral ITinteger
+ -> Int -> Int
+ -> (Integer, (Char->Int)) -> Action
+tok_num = tok_integral itint
+ where
+ itint st@(SourceText ('-':str)) val = ITinteger (((IL $! st) $! True) $! val)
+ itint st@(SourceText str ) val = ITinteger (((IL $! st) $! False) $! val)
+ itint st@(NoSourceText ) val = ITinteger (((IL $! st) $! (val < 0)) $! val)
+
tok_primint :: (Integer -> Integer)
-> Int -> Int
-> (Integer, (Char->Int)) -> Action
tok_primint = tok_integral ITprimint
+
+
tok_primword :: Int -> Int
-> (Integer, (Char->Int)) -> Action
tok_primword = tok_integral ITprimword positive
@@ -1299,12 +1306,14 @@ hexadecimal = (16,hexDigit)
-- readRational can understand negative rationals, exponents, everything.
tok_float, tok_primfloat, tok_primdouble :: String -> Token
-tok_float str = ITrational $! readFractionalLit str
-tok_primfloat str = ITprimfloat $! readFractionalLit str
-tok_primdouble str = ITprimdouble $! readFractionalLit str
+tok_float str = ITrational $! readFractionalLit str
+tok_primfloat str = ITprimfloat $! readFractionalLit str
+tok_primdouble str = ITprimdouble $! readFractionalLit str
readFractionalLit :: String -> FractionalLit
-readFractionalLit str = (FL $! str) $! readRational str
+readFractionalLit str = ((FL $! (SourceText str)) $! is_neg) $! readRational str
+ where is_neg = case str of ('-':_) -> True
+ _ -> False
-- -----------------------------------------------------------------------------
-- Layout processing