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