Skip to content

Commit

Permalink
WIP: Create basic parsing loop for float thousand separators
Browse files Browse the repository at this point in the history
  • Loading branch information
eimfach committed Dec 6, 2019
1 parent e539cf2 commit 941ddf4
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/elm/Parsers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

2 comments on commit 941ddf4

@0pdd
Copy link

@0pdd 0pdd commented on 941ddf4 Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1-09d74669 discovered in src/elm/Parsers.elm and submitted as #2. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 941ddf4 Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1-32b77974 discovered in src/elm/Parsers.elm and submitted as #3. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.