numbers: make double non base-sensitive

This commit is contained in:
Nathan McCarty 2025-01-25 02:24:40 -05:00
parent 026476dd91
commit aacabb8b22

View file

@ -96,9 +96,10 @@ integerBase10 = integer base10
### Double ### Double
```idris ```idris
-- TODO: Replicate `parseDouble` logic and make this base-generic
export export
double : Base -> Parser Double double : Parser Double
double b = do double = do
starting_state <- save starting_state <- save
integer <- integer integer <- integer
fraction <- tryMaybe fraction fraction <- tryMaybe fraction
@ -119,7 +120,7 @@ double b = do
where where
parseDigit : Parser Char parseDigit : Parser Char
parseDigit = do parseDigit = do
GotChar char <- parseChar (hasDigit b) id GotChar char <- parseChar (hasDigit base10) id
| GotError e => throwParseError "\{show e} is not a digit" | GotError e => throwParseError "\{show e} is not a digit"
| EndOfInput => throwParseError "End Of Input" | EndOfInput => throwParseError "End Of Input"
pure char pure char
@ -144,10 +145,6 @@ double b = do
error <- replaceError "Expected digit" error <- replaceError "Expected digit"
digits <- map forget $ atLeastOne error parseDigit digits <- map forget $ atLeastOne error parseDigit
pure . pack $ sign :: digits pure . pack $ sign :: digits
export
doubleBase10 : Parser Double
doubleBase10 = double base10
``` ```
## Unit tests ## Unit tests
@ -215,7 +212,7 @@ compareDouble string = do
putStrLn "Failed to produce parser for \{string}" putStrLn "Failed to produce parser for \{string}"
pure False pure False
Right result <- Right result <-
runEff (rundownFirst doubleBase10) [handleParserStateIO state] {m = IO} runEff (rundownFirst double) [handleParserStateIO state] {m = IO}
| Left err => do | Left err => do
printLn err printLn err
pure False pure False