Package [root]

Types

Link copied to clipboard
sealed class Option<T>

Represents a single value, or nothing

Link copied to clipboard
interface Parseable

Input to the parser

Link copied to clipboard
typealias Parser<T> = (Parseable) -> ParserOutput<T>?

A parser takes an input, which is parseable, and returns a typed output

Link copied to clipboard
typealias ParserOutput<T> = Pair<Parseable, T>

A parser returns the remaining unparsed input and the typed result of parsing the input

Link copied to clipboard
data class StringParseable(string: String, index: Int) : Parseable

Wraps a string with a pointer to the head of the remaining unparsed input to prevent repeatedly creating substrings

Functions

Link copied to clipboard
fun <T> Parser<T>.atLeastOne(): (Parseable) -> ParserOutput<List<T>>?

Returns a parser that consumes 1 or more

Link copied to clipboard
fun <T, S> Parser<T>.between(p: Parser<S>): (Parseable) -> ParserOutput<T>?

Returns a parser for input surrounded the same parser to the left and to the right

fun <T, S, U> Parser<T>.between(p: Pair<Parser<S>, Parser<U>>): (Parseable) -> ParserOutput<T>?
fun <T, S, U> Parser<T>.between(left: Parser<S>, right: Parser<U>): (Parseable) -> ParserOutput<T>?

Returns a parser for input surrounded by a pair of parsers

Link copied to clipboard
fun <T, S> Parser<T>.bind(fn: (T) -> Parser<S>): (Parseable) -> ParserOutput<S>?

Flattens multiple parsers (called flatMap elsewhere)

Link copied to clipboard
fun char(c: Char): (Parseable) -> Pair<Parseable, Char>?

A parser that consumes the given character

Link copied to clipboard
fun <T> defer(fn: () -> Parser<T>): (Parseable) -> ParserOutput<T>?

Defers constructing a parser until it's needed. Useful when parsers create circular references

Link copied to clipboard
fun <T, S> Parser<T>.delimitedBy(delimiter: Parser<S>): (Parseable) -> ParserOutput<List<T>>?

Returns a parser for input separated by a delimiter, e.g. 1,2,3

Link copied to clipboard
fun <S, T> Parser<S>.except(next: Parser<T>): Parser<S>

Given this parser, will return a parser that fails if the other parser succeeds

Link copied to clipboard
fun <T> fail(): Parser<T>

Returns a parser that always fails

Link copied to clipboard
fun <T> Iterable<Parser<T>>.first(): (Parseable) -> ParserOutput<T>?

Returns a parser that returns the first successful result

Link copied to clipboard
fun main(args: Array<String>)
Link copied to clipboard
fun <T> Parser<T>.many(): Parser<Iterable<T>>

Returns a parser that consumes 0 or more

Link copied to clipboard
fun <S, T> Parser<S>.map(fn: (S) -> T): Parser<T>

Maps a parser output to a new value

Link copied to clipboard
fun <S, T> Parser<S>.mapTo(value: T): Parser<T>

Maps a parser output to a new value

Link copied to clipboard
fun <T> Parser<T>.optional(): (Parseable) -> Pair<Parseable, Option<T>>

Returns a parser that always succeeds and returns the optional value if input was consumed

Link copied to clipboard
fun <T> Parser<T>.or(alternative: Parser<T>): (Parseable) -> ParserOutput<T>?

Returns a parser that returns the first successful result

Link copied to clipboard
fun <T> Parser<T>.parse(input: String): T

Helper function to actually run the parser

Link copied to clipboard
fun String.parseable(index: Int = 0): StringParseable

Helper function to wrap a string for input to a parser

Link copied to clipboard
fun <T> Parser<T>.peek(): (Parseable) -> Pair<Parseable, T>?

Returns a parser that does not consume input, even if it succeeds

Link copied to clipboard
fun <T> pure(default: T): (Parseable) -> Pair<Parseable, T>

Returns a parser that always succeeds. The result is the unconsumed input and the value passed to this function

Link copied to clipboard
fun sat(fn: (Char) -> Boolean): (Parseable) -> Pair<Parseable, Char>?

Parses a character successfully if the given predicate returns true

Link copied to clipboard
fun <T, S> Parser<T>.skipLeft(next: Parser<S>): (Parseable) -> ParserOutput<S>?

Returns a parser that ignores the successful result of this

Link copied to clipboard
fun <T, S> Parser<T>.skipRight(next: Parser<S>): (Parseable) -> ParserOutput<T>?

Returns a parser that uses this parser's output, ignoring the successful result of the next

Link copied to clipboard
fun symbol(value: String): Parser<String>

Returns a parser that consumes a given string

Link copied to clipboard
fun Parser<Iterable<Char>>.text(): (Parseable) -> ParserOutput<String>?

Returns a parser that joins a parsed collection of characters to a string

Link copied to clipboard
fun <T> Parser<T>.token(): (Parseable) -> ParserOutput<T>?

Consumes the whitespace around a given parser

Link copied to clipboard
fun <S, T> Parser<S>.until(next: Parser<T>): Parser<Iterable<S>>

Returns a parser that consumes until another parser is successful

Properties

Link copied to clipboard
val alpha: (Parseable) -> Pair<Parseable, Char>?

A parser that consumes a letter

Link copied to clipboard
val char: (Parseable) -> Pair<Parseable, Char>?

A parser that consumes any character

Link copied to clipboard
val decimal: (Parseable) -> ParserOutput<Double>?

A parser that consumes a decimal number

Link copied to clipboard
val digit: (Parseable) -> Pair<Parseable, Char>?

A parser that consumes a digit

Link copied to clipboard
val integer: (Parseable) -> ParserOutput<Int>?

A parser that consumes a positive or negative whole number

Link copied to clipboard
val number: (Parseable) -> ParserOutput<Int>?

A parser that consumes at least one digit to create a number

Link copied to clipboard
val whitespace: (Parseable) -> Pair<Parseable, Char>?

A parser that consumes a whitespace character according to the unicode standard