LineCursor

class LineCursor(lines: List<Line>, val index: Int)

An immutable view over the lines of a source, positioned at one of them. Recognizers receive a cursor and never mutate it, so no state is shared between them.

Parameters

lines

every line of the source

index

index of the line the cursor points at

Constructors

Link copied to clipboard
constructor(lines: List<Line>, index: Int)

Properties

Link copied to clipboard

The line the cursor points at.

Link copied to clipboard
val index: Int
Link copied to clipboard

Amount of lines from the cursor to the end of the source, the current one included.

Functions

Link copied to clipboard
fun at(offset: Int): LineCursor?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun <T : Any> LineCursor.extendThrough(from: Int = 1, end: BlockEnd = BlockEnd.BEFORE_TERMINATOR, closes: (Line) -> T?): Pair<BlockExtent, T>?

Resolves an extent that grows up to and including the first line closes accepts, which is the shape of every fenced block.

Link copied to clipboard
fun LineCursor.extendToEnd(end: BlockEnd = BlockEnd.BEFORE_TERMINATOR): BlockExtent

Covers every line left, which is where a block that never closes ends.

Link copied to clipboard
fun LineCursor.extendWhile(from: Int = 1, end: BlockEnd = BlockEnd.BEFORE_TERMINATOR, continues: (LineCursor) -> Boolean): BlockExtent

Resolves an extent that grows for as long as continues accepts the line after it. Paragraphs, block quotes, footnote definitions, table rows and blank runs differ only in the predicate and in end.

Link copied to clipboard
fun LineCursor.extent(lineCount: Int = 1, end: BlockEnd = BlockEnd.BEFORE_TERMINATOR): BlockExtent

Resolves an extent of a known amount of lines.

Link copied to clipboard
fun lineCountThrough(index: Int): Int?
Link copied to clipboard

Builds a match from a resolved BlockExtent.

fun LineCursor.match(lineCount: Int, endIndex: Int, wrap: (TokenData) -> Token): BlockMatch

Builds a match whose token covers the source from the cursor's line up to endIndex. Prefer the BlockExtent overload, which resolves the line count and the end together. This one serves the kinds whose text is not line-aligned: the comment, the page break and the zero-width function call flag.

Link copied to clipboard
fun peek(offset: Int): Line?
Link copied to clipboard
fun spanTo(lineCount: Int): Int