Parsley

object Parsley

This object contains the core "function-style" combinators as well as the implicit classes which provide the "method-style" combinators. All parsers will likely require something from within!

This object contains the core "function-style" combinators as well as the implicit classes which provide the "method-style" combinators. All parsers will likely require something from within!

Companion
class
class Object
trait Matchable
class Any

Type members

Classlikes

final class LazyChooseParsley[P, +A](pq: => (P, P))(con: P => Parsley[A])

This class exposes a ternary operator on pairs of parsers.

This class exposes a ternary operator on pairs of parsers.

Value Params
con

A conversion (if required) to turn elements of pq into parsers

pq

The parsers which serve the branches of the if

Version

1.0.0

final class LazyMapParsley[-A, +B](f: A => B)

This class exposes the <#> combinator on functions.

This class exposes the <#> combinator on functions.

Value Params
f

The function that is used for the map

Version

1.0.0

final class LazyParsley[P, +A](p: => P)(con: P => Parsley[A])

This class exposes the commonly used combinators in Parsley. For a description of why the library is designed in this way, see: the Parsley wiki

This class exposes the commonly used combinators in Parsley. For a description of why the library is designed in this way, see: the Parsley wiki

Value Params
con

A conversion (if required) to turn p into a parser

p

The parser which serves as the method receiver

Version

1.0.0

Value members

Concrete methods

def attempt[A](p: => Parsley[A]): Parsley[A]

Given a parser p, attempts to parse p. If the parser fails, then attempt ensures that no input was consumed. This allows for backtracking capabilities, disabling the implicit cut semantics offered by <|>.

Given a parser p, attempts to parse p. If the parser fails, then attempt ensures that no input was consumed. This allows for backtracking capabilities, disabling the implicit cut semantics offered by <|>.

Value Params
p

The parser to run

Returns

The result of p, or if p failed ensures the parser state was as it was on entry.

def branch[A, B, C](b: => Parsley[Either[A, B]], p: => Parsley[A => C], q: => Parsley[B => C]): Parsley[C]

This is one of the core operations of a selective functor. It will conditionally execute one of p and q depending on the result from b. This can be used to implement conditional choice within a parser without relying on expensive monadic operations.

This is one of the core operations of a selective functor. It will conditionally execute one of p and q depending on the result from b. This can be used to implement conditional choice within a parser without relying on expensive monadic operations.

Value Params
b

The first parser to parse

p

If b returns Left then this parser is executed with the result

q

If b returns Right then this parser is executed with the result

Returns

Either the result from p or q depending on b.

def join[A](p: => Parsley[Parsley[A]]): Parsley[A]

This function is an alias for _.flatten. Provides namesake to Haskell.

This function is an alias for _.flatten. Provides namesake to Haskell.

def lookAhead[A](p: => Parsley[A]): Parsley[A]

Parses p without consuming any input. If p fails and consumes input then so does lookAhead(p). Combine with attempt if this is undesirable.

Parses p without consuming any input. If p fails and consumes input then so does lookAhead(p). Combine with attempt if this is undesirable.

Value Params
p

The parser to look ahead at

Returns

The result of the lookahead

def notFollowedBy(p: Parsley[_]): Parsley[Unit]

notFollowedBy(p) only succeeds when parser p fails. This parser does not consume any input. This parser can be used to implement the 'longest match' rule. For example, when recognising keywords, we want to make sure that a keyword is not followed by a legal identifier character, in which case the keyword is actually an identifier. We can program this behaviour as follows:

notFollowedBy(p) only succeeds when parser p fails. This parser does not consume any input. This parser can be used to implement the 'longest match' rule. For example, when recognising keywords, we want to make sure that a keyword is not followed by a legal identifier character, in which case the keyword is actually an identifier. We can program this behaviour as follows:

attempt(kw *> notFollowedBy(alphaNum))
def pure[A](x: A): Parsley[A]

This is the traditional applicative pure function (or monadic return) for parsers. It consumes no input and does not influence the state of the parser, but does return the value provided. Useful to inject pure values into the parsing process.

This is the traditional applicative pure function (or monadic return) for parsers. It consumes no input and does not influence the state of the parser, but does return the value provided. Useful to inject pure values into the parsing process.

Value Params
x

The value to be returned from the parser

Returns

A parser which consumes nothing and returns x

def select[A, B](p: => Parsley[Either[A, B]], q: => Parsley[A => B]): Parsley[B]

This is one of the core operations of a selective functor. It will conditionally execute one of q depending on whether or not p returns a Left. It can be used to implement branch and other selective operations, however it is more efficiently implemented with branch itself.

This is one of the core operations of a selective functor. It will conditionally execute one of q depending on whether or not p returns a Left. It can be used to implement branch and other selective operations, however it is more efficiently implemented with branch itself.

Value Params
p

The first parser to parse

q

If p returns Left then this parser is executed with the result

Returns

Either the result from p if it returned Left or the result of q applied to the Right from p

def sequence[A](ps: Parsley[A]*): Parsley[List[A]]

Evaluate each of the parsers in ps sequentially from left to right, collecting the results.

Evaluate each of the parsers in ps sequentially from left to right, collecting the results.

Value Params
ps

Parsers to be sequenced

Returns

The list containing results, one from each parser, in order

def skip(ps: Parsley[_]*): Parsley[Unit]

Evaluate each of the parsers in ps sequentially from left to right, ignoring the results.

Evaluate each of the parsers in ps sequentially from left to right, ignoring the results.

Value Params
ps

Parsers to be performed

def traverse[A, B](f: A => Parsley[B], xs: A*): Parsley[List[B]]

Like sequence but produces a list of parsers to sequence by applying the function f to each element in xs.

Like sequence but produces a list of parsers to sequence by applying the function f to each element in xs.

Value Params
f

The function to map on each element of xs to produce parsers

xs

Values to generate parsers from

Returns

The list containing results formed by executing each parser generated from xs and f in sequence

def void(p: Parsley[_]): Parsley[Unit]

converts a parser's result to ()

converts a parser's result to ()

Concrete fields

val col: Parsley[Int]

This parser consumes no input and returns the current column number reached in the input stream

This parser consumes no input and returns the current column number reached in the input stream

Returns

The column number the parser is currently at

val empty: Parsley[Nothing]

The empty parser consumes no input and fails softly (that is to say, no error message)

The empty parser consumes no input and fails softly (that is to say, no error message)

val line: Parsley[Int]

This parser consumes no input and returns the current line number reached in the input stream

This parser consumes no input and returns the current line number reached in the input stream

Returns

The line number the parser is currently at

val pos: Parsley[(Int, Int)]

This parser consumes no input and returns the current position reached in the input stream

This parser consumes no input and returns the current position reached in the input stream

Returns

Tuple of line and column number that the parser has reached

val unit: Parsley[Unit]

Returns (). Defined as pure(()) but aliased for sugar

Returns (). Defined as pure(()) but aliased for sugar