Skip to content

Commit

Permalink
Revert "add: explicit float and doubles"
Browse files Browse the repository at this point in the history
  • Loading branch information
oriollinan authored Jan 17, 2025
1 parent a31e72f commit 942f58e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 29 deletions.
10 changes: 3 additions & 7 deletions lib/Ast/Parser/Literal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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`.
Expand Down
1 change: 0 additions & 1 deletion lib/Ast/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ data SrcLoc = SrcLoc
data Literal
= LInt Integer
| LFloat Double
| LDouble Double
| LChar Char
| LBool Bool
| LArray [Literal]
Expand Down
1 change: 0 additions & 1 deletion lib/Codegen/ExprGen/Variable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 2 additions & 20 deletions test/Ast/Parser/LiteralSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 942f58e

Please # to comment.