🌳
Walking though the Elm woods
  • Introduction
  • Structure of the book
  • Frequently asked questions
    • How can different types share data?
    • How to break Dependency Cycles?
    • How to structure an Elm project?
    • How to turn a Msg into a Cmd Msg?
    • How to update nested Records?
    • What are comparable types?
    • Why are Booleans bad?
    • 🔜Future topics
  • Recipes
    • Writing a Single Page Application
      • Share state across pages
      • Debounced Validation
      • Reusable views
    • Making impossible states Impossible
      • Non empty lists using Zippers
      • Restrict records using Opaque Types
      • Write safer functions using Phantom Types
    • Designing Elm package APIs
      • Create upwards compatible APIs
    • 🔜Future topics
  • Frameworks and packages
    • elm/parser
    • mdgriffith/elm-ui
    • 🔜Future topics
Powered by GitBook
On this page
  • Basics
  • Pipeline
  • Strings
  • Loops
  • Error messages
  • Further Reading

Was this helpful?

  1. Frameworks and packages

elm/parser

PreviousFuture topicsNextmdgriffith/elm-ui

Last updated 5 years ago

Was this helpful?

Regular expressions are quite confusing and difficult to use. This library provides a coherent alternative that handles more cases and produces clearer code.

(Readme.md from the )

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

point : Parser Point
point =
  succeed Point
    |. symbol "("
    |. spaces
    |= float
    |. spaces
    |. symbol ","
    |. spaces
    |= float
    |. spaces
    |. symbol ")"

This is a summary of the talk by Tereza Sokol.

Basics

Function

Description

Runs the Parser on a String

Parser for Int

Parser for Float

Trys different Parsers. Uses the first that succeeds.

Once the parser matches the first element, there is no going back!

Applys the first parser and if successful applies the second. Fails if one of the parsers fails.

Pipeline

Function

Description

Starts the Pipeline. a -> Parser a is the constructor.

For a record Point use the structur called Point .

Keeps an element.

Eats a character and throws it away.

Represents whitespace

Strings

Function

Description

Looks for zero or more characters that succeeds the check. Stops as soon as the check fails.

Reads one symbols.

Returnes the string that got chomped

Loops

Function

Description

Takes an initial state and a parser step and returns a parser.

A parser step just specifies if it should continue looping or stop.

Error messages

Function

Description

Returns the error message and ends the parsing. The argument is the actuall message.

Further Reading

: Parser a -> String -> Result (List DeadEnd) a

: Parser Int

: Parser Float

: List (Parser a) -> Parser a

: (a -> Parser b) -> Parser a -> Parser b

This subject is explained at .

: a -> Parser a

: Parser (a -> b) -> Parser a -> Parser b

: Parser keep -> Parser ignore -> Parser keep

: Parser ()

This subject is explained at .

: (Char -> Bool) -> Parser ()

: (Char -> Bool) -> Parser ()

: Parser a -> Parser String

This subject is explained at .

: state -> (state -> Parser ( state a)) -> Parser a

type state a = Loop state | Done a

This subject is explained at .

: String -> Parser a

🎥Video: by Tereza Sokol

📄Thread:

package
Demystifying Parsers
4:48 in the Video
7:20 in the Video
14:10 in the Video
17:04 in the Video
Demystifying Parsers
Elm parser question
run
int
float
oneOf
andThen
succeed
(|=)
(|.)
spaces
chompWhile
chompIf
getChompedString
loop
Step
Step
problem