Module

Data.Eulalie.Parser

Package
purescript-eulalie
Repository
bodil/purescript-eulalie

#parse Source

parse :: forall o i. Parser i o -> Stream i -> ParseResult i o

Run a parse operation on a stream.

#succeed Source

succeed :: forall o i. o -> Parser i o

The succeed parser constructor creates a parser which will simply return the value provided as its argument, without consuming any input.

This is equivalent to the monadic pure.

#fail Source

fail :: forall o i. Parser i o

The fail parser will just fail immediately without consuming any input.

#failAt Source

failAt :: forall o i. Stream i -> Parser i o

The failAt parser will fail immediately without consuming any input, but will report the failure at the provided input position.

#expected Source

expected :: forall o i. Parser i o -> String -> Parser i o

A parser combinator which returns the provided parser unchanged, except that if it fails, the provided error message will be returned in the ParseError.

#item Source

item :: forall i. Parser i i

The item parser consumes a single value, regardless of what it is, and returns it as its result.

#cut Source

cut :: forall o i. Parser i o -> Parser i o

The cut parser combinator takes a parser and produces a new parser for which all errors are fatal, causing either to stop trying further parsers and return immediately with a fatal error.

#cutWith Source

cutWith :: forall b a i. Parser i b -> Parser i a -> Parser i a

Takes two parsers p1 and p2, returning a parser which will match p1 first, discard the result, then either match p2 or produce a fatal error.

#seq Source

seq :: forall b a i. Parser i a -> (a -> Parser i b) -> Parser i b

The seq combinator takes a parser, and a function which will receive the result of that parser if it succeeds, and which should return another parser, which will be run immediately after the initial parser. In this way, you can join parsers together in a sequence, producing more complex parsers.

This is equivalent to the monadic bind operation.

#either Source

either :: forall o i. Parser i o -> Parser i o -> Parser i o

The either combinator takes two parsers, runs the first on the input stream, and if that fails, it will backtrack and attempt the second parser on the same input. Basically, try parser 1, then try parser 2.

If the first parser fails with an error flagged as fatal (see cut), the second parser will not be attempted.

This is equivalent to the alt operation of MonadPlus/Alt.

#withStart Source

withStart :: forall o i. Parser i o -> Parser i (Tuple o (Stream i))

Converts a parser into one which will return the point in the stream where it started parsing in addition to its parsed value.

Useful if you want to keep track of where in the input stream a parsed token came from.

#sat Source

sat :: forall i. (i -> Boolean) -> Parser i i

The sat parser constructor takes a predicate function, and will consume a single character if calling that predicate function with the character as its argument returns true. If it returns false, the parser will fail.

#maybe Source

maybe :: forall o i. Monoid o => Parser i o -> Parser i o

The maybe parser combinator creates a parser which will run the provided parser on the input, and if it fails, it will returns the empty value (as defined by mempty) as a result, without consuming any input.

#eof Source

eof :: forall i. Parser i Unit

Matches the end of the stream.

#many Source

many :: forall o i. Parser i o -> Parser i (List o)

The many combinator takes a parser, and returns a new parser which will run the parser repeatedly on the input stream until it fails, returning a list of the result values of each parse operation as its result, or the empty list if the parser never succeeded.

Read that as "match this parser zero or more times and give me a list of the results."

#many1 Source

many1 :: forall o i. Parser i o -> Parser i (List o)

The many1 combinator is just like the many combinator, except it requires its wrapped parser to match at least once. The resulting list is thus guaranteed to contain at least one value.

#sepBy Source

sepBy :: forall b a i. Parser i a -> Parser i b -> Parser i (List b)

Matches the provided parser p zero or more times, but requires the parser sep to match once in between each match of p. In other words, use sep to match separator characters in between matches of p.

#sepBy1 Source

sepBy1 :: forall b a i. Parser i a -> Parser i b -> Parser i (List b)

Matches the provided parser p one or more times, but requires the parser sep to match once in between each match of p. In other words, use sep to match separator characters in between matches of p.

#sepByCut Source

sepByCut :: forall b a i. Parser i a -> Parser i b -> Parser i (List b)

Like sepBy, but cut on the separator, so that matching a sep not followed by a p will cause a fatal error.