Scanner

class Scanner(val source: CharSequence, val limit: Int = source.length, var index: Int = 0)

A cursor over a bounded slice of a source.

Parameters

source

the text to scan

limit

index just past the last character the scanner may read

index

index of the character the scanner points at

Constructors

Link copied to clipboard
constructor(source: CharSequence, limit: Int = source.length, index: Int = 0)

Properties

Link copied to clipboard
var index: Int
Link copied to clipboard

Whether the scanner has reached its limit.

Link copied to clipboard
val limit: Int
Link copied to clipboard

Functions

Link copied to clipboard

Consumes one character.

Link copied to clipboard
fun <T : Any> attempt(block: Scanner.() -> T?): T?

Runs block, keeping what it consumed when it returns a value and rewinding when it returns null.

Link copied to clipboard
fun <T> lookahead(block: Scanner.() -> T): T

Runs block and always rewinds, so the scanner only looks and never consumes.

Link copied to clipboard
fun mark(): Int
Link copied to clipboard
fun peek(offset: Int = 0): Char?
Link copied to clipboard
fun previous(): Char?

Reads the neighbouring character even when it lies before the slice's own start, which is what a boundary rule needs.

Link copied to clipboard
fun repeatWhile(block: Scanner.() -> Boolean): Int

Repeats block as a step while it succeeds, so a failed iteration consumes nothing. An iteration that succeeds without consuming anything ends the loop and is not counted, because repeating it could never terminate.

Link copied to clipboard
fun sliceFrom(mark: Int): String
Link copied to clipboard
fun step(block: Scanner.() -> Boolean): Boolean

Runs block, keeping what it consumed when it returns true and rewinding when it returns false.

Link copied to clipboard
fun take(char: Char): Boolean
fun take(text: String, ignoreCase: Boolean = false): Boolean
Link copied to clipboard

Consumes a backtick-delimited span, which a label treats as opaque.

Link copied to clipboard

Consumes a {#identifier} suffix.

Link copied to clipboard

Consumes a title enclosed in double quotes, single quotes or parentheses. A backslash escapes the next character, and the closing delimiter may not appear unescaped inside. The title may span lines, but not a blank one, since the construct it belongs to ends where a paragraph does.

Link copied to clipboard

Consumes a backslash and the character it escapes, which may not be a line terminator.

Link copied to clipboard
fun takeIf(predicate: (Char) -> Boolean): Boolean
Link copied to clipboard
fun <T : Any> Scanner.takeLabel(closes: Scanner.() -> T?): Pair<String, T>?

Consumes the bracketed label shared by links, reference links, images and reference images.

Link copied to clipboard

Consumes a parenthesized destination with its optional title.

Link copied to clipboard
fun Scanner.takeOnelineMath(accepts: Scanner.() -> Boolean = { true }): String?

Consumes a one-line math expression. It opens with a dollar sign and one space or tab and closes with one space or tab and a dollar sign; an inner dollar sign belongs to the expression as long as it is not adjacent to whitespace.

Link copied to clipboard

Consumes everything up to the limit.

Link copied to clipboard
fun takeRun(char: Char): Int
Link copied to clipboard
Link copied to clipboard
fun takeWhile(predicate: (Char) -> Boolean): Int

Consumes every character satisfying predicate.