davidcavazos/parser/1.0.0

NOTE: the latest version is 7.0.0

Renamed to lambda-phi/parser. It is published under that name, and new versions come out there.

Versions published as davidcavazos/parser still install under that name. 2 versions of 12 come from the new location (see their notes). 10 versions could not be recovered and cannot be installed.

Rerouted (renamed, needs approval). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/lambda-phi/parser.

What we checked: The repo moved to github.com/lambda-phi/parser and tag 1.0.0 is there; its commit 8d78c50fb0d7 is from 2021-03-04 22:53 UTC, after the version was published (2020-09-03 22:24 UTC); elm.json differs from package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.

We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:

  • lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,
  • LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,
  • LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.

Details · package.elm-lang.org's zip: https://github.com/davidcavazos/parser/zipball/1.0.0/

Parser

An easy to use general-purpose parser for Elm.

This library aims to provide a clean and intuitive parsing library with good error messages out of the box.

ℹ️ This has been inspired by the elm/parser and dasch/parser libraries.

How to use

A good place to start is by defining the data type you want to parse into. Then, it's a good idea to define a function to parse into that data type.

Here's a simple example to parse an 2D point, like (42, 3.14).

import Parser exposing (Parser, drop, into, parse, succeed, take)
import Parser.Char exposing (char)
import Parser.Common exposing (number, spaces)
import Parser.Error

type alias Point =
    { x : Float
    , y : Float
    }

point : Parser Point
point =
    into "Point"
        (succeed Point
            |> drop (char '(')
            |> drop spaces
            |> take number
            |> drop spaces
            |> drop (char ',')
            |> drop spaces
            |> take number
            |> drop spaces
            |> drop (char ')')
        )

-- Here's how a successful parse looks like.
parse "(2.71, 3.14)" point --> Ok {x = 2.71, y = 3.14}

-- And we can get a nice error message if it fails.
point
    |> parse "(2.71, x)"
    |> Result.mapError (Parser.Error.dump "filename.txt")
--> Err
-->     [ "[ERROR] filename.txt:1:8: I was expecting a digit [0-9]. I got stuck when I got the character 'x'."
-->     , "  in Point at line 1:1"
-->     , ""
-->     , "1|(2.71, x)"
-->     , "  ~~~~~~~^"
-->     ]

Usage

For more detailed documentation of the functions available an code examples on how to use them, check the modules: