From 941ddf4974ff51824fd8b14f9d0647360e7eeaba Mon Sep 17 00:00:00 2001 From: Robin Gruenke Date: Fri, 6 Dec 2019 16:10:12 +0100 Subject: [PATCH] WIP: Create basic parsing loop for float thousand separators --- src/elm/Parsers.elm | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/elm/Parsers.elm b/src/elm/Parsers.elm index df78546..d642968 100644 --- a/src/elm/Parsers.elm +++ b/src/elm/Parsers.elm @@ -89,13 +89,26 @@ parseInt = ] -{-| @todo #1 Used to Parse a float in a chain of other parsers. Supporting `,` _and_ `.` decimal separators. +parseFloatLoop : Parser.Parser (List String) +parseFloatLoop = + Parser.loop [] floatHelp -Parsing Float Strings with additional thousands separators is not supported. The parsing will fail in this scenario. -Consider using `Parser.loop` and `Parser.oneOf`. Also I think it should test if the created number is supported by the js runtime. -There is an elm lib to do this. Maybe it is easy to implement it by yourself, and the lib is not needed. Also, should mixed separator 'types' be possible ? -or could it cause a performance issue ? Right now it supports mixed decimal separators using `Parser.oneOf` +{-| @todo #1 Complete & Integrate this into the float parsing chain +-} +floatHelp : List String -> Parser.Parser (Parser.Step (List String) (List String)) +floatHelp intList = + Parser.oneOf + [ Parser.succeed (\aInt -> Parser.Loop (aInt :: intList)) + |= Parser.getChompedString (Parser.chompWhile Char.isDigit) + |. Parser.symbol "." + , Parser.succeed () + |> Parser.map (\_ -> Parser.Done (List.reverse intList)) + ] + + +{-| Used to Parse a float in a chain of other parsers. Supporting `,` _and_ `.` decimal separators. +@todo #1 Parsing Float Strings with additional thousands separators is not supported. The parsing will fail in this scenario. Consider using `Parser.loop` and `Parser.oneOf`. Also I think it should test if the created number is supported by the js runtime. There is an elm lib to do this. Maybe it is easy to implement it by yourself, and the lib is not needed. Also, should mixed separator 'types' be possible ? or could it cause a performance issue ? Right now it supports mixed decimal separators using `Parser.oneOf` -} parseChainFloat : Parser.Parser ( String, String, String ) parseChainFloat =