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.
- Line
Index - Maps byte offsets to line/column positions.
- NodeId
- An index into a
SyntaxTree’s node arena. - Syntax
Error - A problem found while turning source text into a tree.
- Syntax
Node - A borrowed handle to one node in a
SyntaxTree. - Syntax
Tree - A parsed GDScript file: the source text plus its tree and diagnostics.
- Text
Range - A half-open byte range into the source text.
- Token
- A lexed token: a kind plus the span of source it covers.
- Tree
Builder - Builds a
SyntaxTreeas the parser walks the token stream.
Enums§
- Element
- A child of a node: either a nested node or a leaf token.
- Syntax
Kind - A syntactic category. Values below
SyntaxKind::FIRST_NODEare tokens.