Package-level declarations

Types

Link copied to clipboard
data class BalanceConfig(val makeTree: (children: List<Any>, positions: List<Int>, length: Int) -> Tree? = null)

Configuration for Tree.balance.

Link copied to clipboard
interface BufferCursor

Abstraction for iterating over a tree buffer. A cursor initially points at the very last element in the buffer. Every time next is called it moves on to the previous one.

Link copied to clipboard
data class ChangedRange(val fromA: Int, val toA: Int, val fromB: Int, val toB: Int)

Represents a changed range for incremental parsing.

Link copied to clipboard
interface Input

Input interface for parsers.

Link copied to clipboard
data class IterateSpec(val enter: (SyntaxNodeRef) -> Boolean?, val leave: (SyntaxNodeRef) -> Unit? = null, val from: Int? = null, val to: Int? = null, val mode: Int? = null)

Specification for Tree.iterate.

Link copied to clipboard
object IterMode

Iteration mode flags.

Link copied to clipboard
data class MountedTree(val tree: Tree, val overlay: List<TextRange>?, val parser: Parser)

Info about a mounted tree inside another tree.

Link copied to clipboard
class NestedParse(val parser: Parser, val overlay: ParseOverlay? = null, val bracketed: Boolean = false)

Objects returned by the function passed to parseMixed should conform to this interface.

Link copied to clipboard
data class NodeIterator(val node: SyntaxNode, val next: NodeIterator?)

Linked list of syntax nodes returned by Tree.resolveStack.

Link copied to clipboard
class NodeProp<T>(val perNode: Boolean = false, val deserialize: (String) -> T? = null, val combine: (T, T) -> T? = null)

Each NodeType or individual Tree can have metadata associated with it in props. Instances of this class represent prop names.

Link copied to clipboard
class NodePropSource<T>(val prop: NodeProp<T>, val f: (NodeType) -> T?)

A source that can provide values for a NodeProp on NodeTypes.

Link copied to clipboard
class NodeSet(val types: List<NodeType>)

An indexed set of NodeTypes with helper methods for extending them with props.

Link copied to clipboard
class NodeType

Each node in a syntax tree has a type, which describes its role and the information associated with it.

Link copied to clipboard
data class NodeTypeSpec(val name: String = "", val id: Int, val props: List<Pair<NodeProp<*>, Any?>> = emptyList(), val top: Boolean = false, val error: Boolean = false, val skipped: Boolean = false)

Spec for constructing a NodeType.

Link copied to clipboard
class NodeWeakMap<T>

Associates values with (syntax) nodes, using their identity as a key. In Kotlin/multiplatform we use a regular HashMap keyed by the backing Tree instance + position, since true WeakReferences aren't available cross-platform.

Link copied to clipboard
sealed interface ParseOverlay

Type-safe representation of a NestedParse overlay.

Link copied to clipboard
sealed interface ParseOverlayMatch

Result returned by a ParseOverlay.Predicate match function.

Link copied to clipboard
abstract class Parser

Abstract base class for parsers.

Link copied to clipboard
typealias ParseWrapper = (parse: PartialParse, input: Input, fragments: List<TreeFragment>, ranges: List<TextRange>) -> PartialParse

Type for a function that wraps a PartialParse in additional logic.

Link copied to clipboard
interface PartialParse

Interface for incremental parsing.

Link copied to clipboard
class StringInput(string: String) : Input

A simple string-based Input implementation.

Link copied to clipboard

A syntax node that provides navigation to parent and siblings.

Link copied to clipboard
interface SyntaxNodeRef

Interface for a reference to a syntax node in a tree.

Link copied to clipboard
data class TextRange(val from: Int, val to: Int)

A range with from/to positions.

Link copied to clipboard
class Tree(val type: NodeType, children: List<Any>, val positions: List<Int>, val length: Int, propValues: Map<Int, Any?> = emptyMap())

A syntax tree. Immutable, constructed by parsers. Children may be Tree or TreeBuffer instances.

Link copied to clipboard
class TreeBuffer(val buffer: IntArray, val length: Int, val set: NodeSet)

Tree buffers contain (type, start, end, endIndex) quads for each node. In such a buffer, nodes are stored in prefix order (parents before children, with the endIndex of the parent indicating which children belong to it).

Link copied to clipboard
sealed interface TreeBuildBuffer

Type-safe representation of a tree buffer source — either a flat List of ints or a BufferCursor for streaming construction.

Link copied to clipboard
data class TreeBuildSpec(val buffer: TreeBuildBuffer, val nodeSet: NodeSet, val topID: Int, val start: Int = 0, val bufferStart: Int = 0, val length: Int? = null, val maxBufferLength: Int = DEFAULT_BUFFER_LENGTH, val reused: List<Tree> = emptyList(), val minRepeatType: Int = -1)

Build specification for tree construction from a buffer cursor or flat buffer.

Link copied to clipboard

Mutable tree walker. Walks a Tree depth-first, handling both Tree and TreeBuffer children.

Link copied to clipboard
class TreeFragment(val from: Int, val to: Int, val tree: Tree, val offset: Int, val openStart: Boolean = false, val openEnd: Boolean = false)

Tree fragments for incremental parsing.

Properties

Link copied to clipboard
const val DEFAULT_BUFFER_LENGTH: Int = 1024

The default maximum length of a TreeBuffer node.

Functions

Link copied to clipboard
fun parseMixed(nest: (node: SyntaxNodeRef, input: Input) -> NestedParse?): ParseWrapper

Create a parse wrapper that, after the inner parse completes, scans its tree for mixed language regions with the nest function, runs the resulting inner parses, and then mounts their results onto the tree.