Skip to main content

Crate ktrs_syntax

Crate ktrs_syntax 

Source
Expand description

Lossless Kotlin syntax tree. Node and token kinds mirror the Kotlin compiler’s PSI element types one-to-one (see kinds.tsv), so trees can be diffed against DebugUtil.psiToString.

Re-exports§

pub use tree::ElementId;
pub use tree::Tree;
pub use tree::TreeBuilder;

Modules§

caught_panic
Ported code mimics a Java exception with a panic, caught where the JVM tool catches the exception (ktlint’s rule boundary, ktfmt’s per-file catch). The default panic hook would still print each one to stderr, which the jar does not; silence_caught_panics keeps those quiet.
tree
Tree: a parsed file as flat preorder arrays. An element (node or token) is its preorder index; navigation is index arithmetic, and token text is a slice of the source. Replaces rowan’s green/red trees, which allocate per node when built and per step when walked (see research/06-tree-library.md for the measurements).

Structs§

MissedTokens
PsiBuilderImpl.prepareLightTree’s LOG.error("Tokens [..] were not inserted into the tree. .."): the tree leaves those tokens out. IntelliJ’s DefaultLogger (what ktfmt and ktlint run with) prints Self::log to stderr and throws AssertionError, which their CLIs don’t catch. Both expand every chameleon before they look for error elements, so it wins over a parse error anywhere in the file (research/24, finding 4).
Parse
A parsed file: the tree plus one message per ERROR_ELEMENT, in tree preorder.
TextRange
A range in text, represented as a pair of TextSize.
TextSize
A measure of text length. Also, equivalently, an index into text.

Enums§

SyntaxKind

Functions§

psi_dump
Renders parse exactly like IntelliJ’s DebugUtil.psiToString(file, true, false), the format of the compiler’s parser fixtures and of tools/psi-dump.