diff --git a/lib/Ast/Parser/Literal.hs b/lib/Ast/Parser/Literal.hs index 656379c..8b25a64 100644 --- a/lib/Ast/Parser/Literal.hs +++ b/lib/Ast/Parser/Literal.hs @@ -28,9 +28,9 @@ parseInt = AT.LInt <$> ML.signed (pure ()) ML.decimal -- | Parses a floating-point literal. -- Returns a `Literal` of type `LFloat`. parseFloat :: PU.Parser AT.Literal -parseFloat = do - decimal <- - ML.signed +parseFloat = + AT.LFloat + <$> ML.signed (pure ()) ( do wholePart <- ML.decimal :: (PU.Parser Integer) @@ -39,10 +39,6 @@ parseFloat = do let value = fromIntegral wholePart + fractional return value ) - type' <- M.optional $ M.choice [AT.LDouble <$ MC.char 'd', AT.LFloat <$ MC.char 'f'] - case type' of - Just t -> return $ t decimal - _ -> return $ AT.LDouble decimal -- | Parses a boolean literal (`true` or `false`). -- Returns a `Literal` of type `LBool`. diff --git a/lib/Ast/Types.hs b/lib/Ast/Types.hs index 7e00d33..27421e4 100644 --- a/lib/Ast/Types.hs +++ b/lib/Ast/Types.hs @@ -12,7 +12,6 @@ data SrcLoc = SrcLoc data Literal = LInt Integer | LFloat Double - | LDouble Double | LChar Char | LBool Bool | LArray [Literal] diff --git a/lib/Codegen/ExprGen/Variable.hs b/lib/Codegen/ExprGen/Variable.hs index fd2f588..85c03a6 100644 --- a/lib/Codegen/ExprGen/Variable.hs +++ b/lib/Codegen/ExprGen/Variable.hs @@ -61,7 +61,6 @@ generateConstant lit loc = case lit of AT.LBool b -> return $ C.Int 1 (if b then 1 else 0) AT.LNull -> return $ C.Null T.i8 AT.LFloat f -> pure $ C.Float (FF.Double (realToFrac f)) - AT.LDouble f -> pure $ C.Float (FF.Double (realToFrac f)) AT.LArray elems -> do let (headElem, _) = M.fromJust $ L.uncons elems case headElem of diff --git a/test/Ast/Parser/LiteralSpec.hs b/test/Ast/Parser/LiteralSpec.hs index fcadf43..32ce9a9 100644 --- a/test/Ast/Parser/LiteralSpec.hs +++ b/test/Ast/Parser/LiteralSpec.hs @@ -37,35 +37,17 @@ spec = do describe "parseFloat" $ do it "parses positive floats" $ do - let input = "123,45f" + let input = "123,45" result <- parse input let expected = Right (AT.LFloat 123.45) result `shouldBe` expected it "parses negative floats" $ do - let input = "-67,89f" + let input = "-67,89" result <- parse input let expected = Right (AT.LFloat (-67.89)) result `shouldBe` expected - it "parses positive double" $ do - let input = "67,89d" - result <- parse input - let expected = Right (AT.LDouble 67.89) - result `shouldBe` expected - - it "parses negative double" $ do - let input = "-67,89d" - result <- parse input - let expected = Right (AT.LDouble (-67.89)) - result `shouldBe` expected - - it "parses a double" $ do - let input = "67,89" - result <- parse input - let expected = Right (AT.LDouble 67.89) - result `shouldBe` expected - it "fails on non-float input" $ do let input = "abc" result <- parse input