Skip to main content

Module syntax

Module syntax 

Source
Expand description

Unified syntax tree types.

This module defines the core tree data structures shared by all docstring styles. Every parsed docstring is represented as a tree of SyntaxNodes (branches) and SyntaxTokens (leaves), each tagged with a SyntaxKind.

The Parsed struct owns the source text and the root node, and provides a convenience pretty_print method for debugging.

§Missing placeholders

A zero-length element is a missing placeholder: the parsers insert one wherever a syntactically expected element is absent from the source (e.g. the TYPE in a (), the CLOSE_BRACKET in a (int, or the DESCRIPTION in a (int):). The equivalence is exact — zero-length ⇔ missing placeholder — and placeholders sit at the offset where the missing element would be inserted, making them the edit API’s insertion anchors. Placeholders are only ever replaced by a real element, never extended in place, and trivia tokens are never zero-length. Parsed::pretty_print renders a missing token as <missing>; use SyntaxToken::is_missing / SyntaxNode::find_missing to detect them programmatically. The invariants are pinned corpus-wide in tests/trivia.rs.

Structs§

Parsed
The result of parsing a docstring.
SyntaxNode
A branch node in the syntax tree.
SyntaxToken
A leaf token in the syntax tree.

Enums§

SyntaxElement
A child element of a SyntaxNode — either a node or a token.
SyntaxKind
Node and token kinds for all docstring styles.

Traits§

Visitor
Trait for visiting syntax tree nodes and tokens.

Functions§

walk_tree
Walk the raw syntax tree depth-first, calling the visitor methods.