Skip to main content

Crate gdck_syntax

Crate gdck_syntax 

Source
Expand description

Lossless lexing and parsing for GDScript.

The tree this crate produces keeps every byte of the input, including whitespace, comments and blank lines. That is a deliberate constraint rather than an implementation detail: a formatter that rewrites one declaration has to leave the comments around it exactly where they were, and a linter that reports a problem has to point at a real byte offset.

Parsing never fails. Malformed input produces SyntaxKind::Error nodes and diagnostics on SyntaxTree::errors, so tools can report several problems per run and editors can work with a half-typed buffer.

§Example

let tree = gdck_syntax::parse("func _ready() -> void:\n\tpass\n");
assert!(!tree.has_errors());
// The source is always recoverable from the tree.
assert_eq!(tree.text(), "func _ready() -> void:\n\tpass\n");

Structs§

Checkpoint
A position in the child buffer that a node can later be opened at.
Descendants
Pre-order iterator over a subtree. See SyntaxNode::descendants.
LexResult
The result of lexing a source file.
LineCol
A 1-based line and column pair, for human-facing diagnostics.
LineIndex
Maps byte offsets to line/column positions.
NodeId
An index into a SyntaxTree’s node arena.
SyntaxError
A problem found while turning source text into a tree.
SyntaxNode
A borrowed handle to one node in a SyntaxTree.
SyntaxTree
A parsed GDScript file: the source text plus its tree and diagnostics.
TextRange
A half-open byte range into the source text.
Token
A lexed token: a kind plus the span of source it covers.
TreeBuilder
Builds a SyntaxTree as the parser walks the token stream.

Enums§

Element
A child of a node: either a nested node or a leaf token.
SyntaxKind
A syntactic category. Values below SyntaxKind::FIRST_NODE are tokens.

Functions§

parse
Parse GDScript source into a lossless tree.
tokenize
Tokenize source.