Package-level declarations

Types

Link copied to clipboard
fun interface Parser<out T>

Type of a parsing function which takes the list of all tokens and the current working position.

Link copied to clipboard
sealed class ParsingResult<out T>

Output from a parser

Link copied to clipboard
data class Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(val first: T1, val second: T2, val third: T3, val fourth: T4, val fifth: T5, val sixth: T6, val seventh: T7, val eighth: T8, val ninth: T9, val tenth: T10)
Link copied to clipboard
data class Tuple4<T1, T2, T3, T4>(val first: T1, val second: T2, val third: T3, val fourth: T4)
Link copied to clipboard
data class Tuple5<T1, T2, T3, T4, T5>(val first: T1, val second: T2, val third: T3, val fourth: T4, val fifth: T5)
Link copied to clipboard
data class Tuple6<T1, T2, T3, T4, T5, T6>(val first: T1, val second: T2, val third: T3, val fourth: T4, val fifth: T5, val sixth: T6)
Link copied to clipboard
data class Tuple7<T1, T2, T3, T4, T5, T6, T7>(val first: T1, val second: T2, val third: T3, val fourth: T4, val fifth: T5, val sixth: T6, val seventh: T7)
Link copied to clipboard
data class Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>(val first: T1, val second: T2, val third: T3, val fourth: T4, val fifth: T5, val sixth: T6, val seventh: T7, val eighth: T8)
Link copied to clipboard
data class Tuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(val first: T1, val second: T2, val third: T3, val fourth: T4, val fifth: T5, val sixth: T6, val seventh: T7, val eighth: T8, val ninth: T9)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun <T> collectTokens(vararg results: T): List<Token>
Link copied to clipboard
fun collectUntil(matchFn: (Token) -> Boolean): Parser<List<Token>>

Collect all tokens from current till any one of them matches the given function.

Link copied to clipboard
fun <T> Parser<T>.debug(name: String? = null): Parser<T>
Link copied to clipboard
fun <T> lazy(parserProvider: () -> Parser<T>): Parser<T>
Link copied to clipboard
fun <T, R> Parser<T>.map(transform: (T) -> R): Parser<R>
fun <T, R> ParsingResult<T>.map(transform: (T) -> R): ParsingResult<R>
Link copied to clipboard
fun matchToken(matchFn: (Token) -> Boolean): Parser<OrgToken>

Match a single token at current position

Link copied to clipboard
fun <T> maybe(parser: Parser<T>): Parser<T?>

Convert a failed result to success with OrgNothing

Link copied to clipboard
fun <T> oneOf(vararg parsers: Parser<T>): Parser<T>

Match one of the parsers and return the result. Order matters.

Link copied to clipboard
fun <T> oneOrMore(parser: Parser<T>): Parser<List<T>>

Run the same parser many times and return results till a failure. This ensures that at least one parse happens.

Link copied to clipboard
fun <T> parsingError(message: String, tokens: List<Token> = emptyList()): ParsingResult.Failure<T>
Link copied to clipboard
fun <T> repeat(min: Int, max: Int?, parser: Parser<T>): Parser<List<T>>

Repeatedly match the parser from min to max (inclusive) count

Link copied to clipboard
fun <T1, T2> seq(parser1: Parser<T1>, parser2: Parser<T2>): Parser<Pair<T1, T2>>

Sequence given parsers and execute them one by one. If any parse fails, stop immediately and return the failed result.

fun <T1, T2, T3> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>): Parser<Triple<T1, T2, T3>>
fun <T1, T2, T3, T4> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>, parser4: Parser<T4>): Parser<Tuple4<T1, T2, T3, T4>>
fun <T1, T2, T3, T4, T5> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>, parser4: Parser<T4>, parser5: Parser<T5>): Parser<Tuple5<T1, T2, T3, T4, T5>>
fun <T1, T2, T3, T4, T5, T6> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>, parser4: Parser<T4>, parser5: Parser<T5>, parser6: Parser<T6>): Parser<Tuple6<T1, T2, T3, T4, T5, T6>>
fun <T1, T2, T3, T4, T5, T6, T7> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>, parser4: Parser<T4>, parser5: Parser<T5>, parser6: Parser<T6>, parser7: Parser<T7>): Parser<Tuple7<T1, T2, T3, T4, T5, T6, T7>>
fun <T1, T2, T3, T4, T5, T6, T7, T8> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>, parser4: Parser<T4>, parser5: Parser<T5>, parser6: Parser<T6>, parser7: Parser<T7>, parser8: Parser<T8>): Parser<Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>, parser4: Parser<T4>, parser5: Parser<T5>, parser6: Parser<T6>, parser7: Parser<T7>, parser8: Parser<T8>, parser9: Parser<T9>): Parser<Tuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> seq(parser1: Parser<T1>, parser2: Parser<T2>, parser3: Parser<T3>, parser4: Parser<T4>, parser5: Parser<T5>, parser6: Parser<T6>, parser7: Parser<T7>, parser8: Parser<T8>, parser9: Parser<T9>, parser10: Parser<T10>): Parser<Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>>
Link copied to clipboard
fun <T1, T2> Parser<T1>.then(f: (T1) -> Parser<T2>): Parser<T2>

Run a parser using result of the previous one

Link copied to clipboard
fun <T1, T2> Parser<T1>.unwindThen(f: (T1) -> Parser<T2>): Parser<T2>

Run T1 parser, if successful, go back and run the T2 parser from original position using the result of T1 for a kind of look ahead effect.

Link copied to clipboard
fun <T> value(output: T): Parser<T>
Link copied to clipboard
fun <T> zeroOrMore(parser: Parser<T>): Parser<List<T>>

Run the same parser many times and return results till a failure.