This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Parser using parser combinators
version 6.2.5
license BSD3
native-modules False
elm-version 0.17.0 <= v < 0.18.0
Tag 6.2.5
Committed At 2016-05-17 09:08:48 UTC
elm-lang/lazy 1.0.0 <= v < 2.0.0 1.0.0
elm-lang/core 4.0.0 <= v < 5.0.0 4.0.5

README

Parser

Parsers convert text sequences into a data structure, for example for handling user input and compiling programming languages.

With this parser combinator you can build parsers in a modular way, building parsers by combining parser functions. Parser functions can either succeed or fail.

Examples

{-| Parse a optional sign, succeeds with a -1 if it matches a minus `Char`, otherwise it returns 1 -}
sign : Parser Int
sign =
    let
        minus =
            map (always -1) (symbol '-')
        plus =
            map (always 1) (symbol '+')
    in
        optional (plus `or` minus) 1

{-| Parse a digit -}
digit : Parser Int
digit =
    let
        charToInt c = Char.toCode c - Char.toCode '0'
    in
        map charToInt (satisfy Char.isDigit)

{-| Parse a natural number -}
natural : Parser Int
natural =
    some digit
    |> map (List.foldl (\b a -> a * 10 + b) 0)


{-| Parse an integer with optional sign -}
integer : Parser Int
integer =
    map (*) sign
    |> andMap natural