Parse

This module contains various generic parsers and combinators

Parser a err

Parser a err : Str -> Result (a, Str) err

A Parser is a function which takes a Str and returns a Result containing a tuple of the matched value and the remaining Str after the match, or an error if the match was not found at the beginning of the Str.

Note that the matched value which is returned does not need to be a Str, but can be transformed in any way.

string : Str -> Parser Str [StringNotFound]

Create a parser that will match a specific string

whitespace : Parser Str [WhitespaceNotFound]

Match a string of one or more consecutive whitespace characters

char : Parser U8 [CharNotFound]

Parse a single character

atomic_grapheme : Parser Str [GraphemeNotFound]

Parse a non-clustered grapheme

digit : Parser U8 [NotADigit]

Parse a digit (converts from ASCII value to integer)

integer : Parser U64 [NotAnInteger]

Parse an integer

float : Parser F64 [NotAFloat]

Parse a floating point number

filter : Parser a , (a -> Bool) -> Parser a [FilteredOut]

Create a parser that will filter out matches that do not satisfy the given predicate

excluding : Parser a , (a -> Bool) -> Parser a [Excluded]

Create a parser that will exclude matches that satisfy the given predicate

map : Parser a , (a -> Result b ) -> Parser b

Convert a parser of one type into a parser of another type using a tranform function which turns the first type into a result of the second type

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

Convert a parser of one type into a parser of another type using a transform function which turns the first type into a parser of the second type

one_or_more : Parser a -> Parser (List a) [LessThanOneFound]

Create a parser which matches one or more occurrences of the given parser

zero_or_more : Parser a -> Parser (List a)

Create a parser which matches zero or more occurrences of the given parser

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

Combine 2 parsers into a single parser that returns a tuple of 2 values

zip_3 : Parser a , Parser b , Parser c -> Parser ( a, b, c )

Combine 3 parsers into a single parser that returns a tuple of 3 values

zip_4 : Parser a , Parser b , Parser c , Parser d -> Parser ( a, b, c, d )

Combine 4 parsers into a single parser that returns a tuple of 4 values

zip_5 : Parser a , Parser b , Parser c , Parser d , Parser e -> Parser ( a, b, c, d, e )

Combine 5 parsers into a single parser that returns a tuple of 5 values

zip_6 : Parser a , Parser b , Parser c , Parser d , Parser e , Parser f -> Parser ( a, b, c, d, e, f )

Combine 6 parsers into a single parser that returns a tuple of 6 values

maybe : Parser a -> Parser (Maybe a)

Convert a parser that can fail into a parser that can return a Maybe

or_else : Parser a err, Parser a err -> Parser a err

Try the first parser, if it fails, try the second parser

one_of : List (Parser a err) -> Parser a [NoMatchFound]

Try each parser in sequence until one succeeds

keep_left : Parser l , Parser r -> Parser l

keep the result of the left parser

keep_right : Parser l , Parser r -> Parser r

keep the result of the right parser

lhs : Parser l , Parser r -> Parser l

keep the result of the "left hand side" parser

rhs : Parser l , Parser r -> Parser r

keep the result of the "right hand side" parser

both : Parser l , Parser r -> Parser ( l, r )

keep the result of both parsers

finalize : Result ( a, Str ) -> Result a [NotConsumed]

Finalize a parser result only if the Str has been fully consumed

finalize_lazy : Result ( a, Str ) err -> Result a err

Finalize a parser result without consuming the remaining Str