Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elm/parser for elm #309

Open
samy-jaziri opened this issue Jun 10, 2024 · 0 comments
Open

Add elm/parser for elm #309

samy-jaziri opened this issue Jun 10, 2024 · 0 comments

Comments

@samy-jaziri
Copy link

This is a useful elm package for parsing strings, replacing in an original way regexp manipulations.
This is a standard elm package, depending only on elm/core.
Practicing elm/parser for every kata which are parsing related, is the best way to get familiar to this core package of the elm language.

For example, in the Hidden "Cubic" numbers kata, char by char manipulation, or regexp manipulation, to parse 3-digit numbers verifying isDigit predicate could be done by a recursive Parser implemented by :

numbers : Parser.Parser ( List String )
numbers = 
  Parser.oneOf 
  [ Parser.succeed (\i l -> if isCubic i then i::l else l )
      |= Parser.getChompedString 
        <| ( Parser.succeed () 
              |. Parser.chompIf Char.isDigit 
              |. Parser.chompIf Char.isDigit 
              |. Parser.chompIf Char.isDigit 
            ) 
      |= Parser.lazy ( \_ -> numbers)
  , Parser.succeed [] 
      |. Parser.end
  , Parser.succeed identity
      |. Parser.chompWhile (Char.isDigit >> not)
      |= Parser.lazy ( \_ -> numbers)
  ]

👍 reaction might help to get this request prioritized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants