Skip to content

Commit

Permalink
Distinguish between Real and Natural by syntax (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg authored Aug 5, 2023
1 parent 7f63aa8 commit 95f36d9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Grace/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import qualified Control.Monad.Combinators as Combinators
import qualified Data.Char as Char
import qualified Data.HashSet as HashSet
import qualified Data.List as List
import qualified Data.Scientific as Scientific
import qualified Data.Text as Text
import qualified Data.Text.Read as Read
import qualified Grace.Location as Location
Expand Down Expand Up @@ -193,12 +192,15 @@ lex name code =
return tokens

number :: Parser Token
number = do
scientific <- lexeme Lexer.scientific

case Scientific.toBoundedInteger scientific of
Nothing -> return (RealLiteral scientific)
Just int -> return (Int int)
number =
try parseInteger <|> parseScientific
where
parseInteger = Int
<$> lexeme Lexer.decimal
<* Megaparsec.notFollowedBy (Megaparsec.Char.char '.')
parseScientific = do
scientific <- lexeme Lexer.scientific
return (RealLiteral scientific)

file :: Parser Token
file = lexeme do
Expand Down
1 change: 1 addition & 0 deletions tasty/data/unit/real-dot-zero-input.ffg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tasty/data/unit/real-dot-zero-output.ffg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tasty/data/unit/real-dot-zero-type.ffg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Real

0 comments on commit 95f36d9

Please sign in to comment.