gdsyntax
A GDScript parser for the gdsuite tools, translated from Godot 4.7's own tokenizer and parser. It accepts and rejects what Godot does, with Godot's error messages, and its tree is lossless: every byte of the file, comments and whitespace included, is in the tree.
use Member;
let tree = parse;
assert!;
assert_eq!;
for member in tree.file.members
parsereturns the tree and the errors, in the order Godot reports them. Lines and columns are 1-based, and columns count characters, not bytes.astgives typed access to the whole tree: declarations, statements, expressions, match patterns and annotations, with typed operators. Every accessor returns anOption, because a file with errors still has a tree; code the parser could not read is kept inErrornodes.literaldecodes literal values the way Godot does: string escapes, raw strings,&"name",^"path", and hexadecimal, binary and1_000numbers.- The tree is a
rowantree.
What it checks
Syntax only. Godot's parser also reports some errors that need scope information, such as a name declared twice. Those are left to Godot itself; tests/godot/semantic-errors.txt lists them. Godot's check for identifiers that look like keywords is not ported either. Nesting deeper than 256 levels is reported as an error, so deeply nested input cannot overflow the stack.
How it is tested
- Godot's own test scripts for 4.7 (in
tests/godot): every script Godot parses parses with no error, and every script Godot rejects gets Godot's first error message, apart from the cases above. - Real projects:
GDSYNTAX_CORPUS=<folders> cargo test -p gdsyntax --test corpuschecks that every file round-trips and parses without errors. - Typed tree: on every valid script, every node of the tree is reachable through
astalone (tests/typed_tree.rs; it also runs onGDSYNTAX_CORPUS). - Broken input: random edits to valid files must never make the parser panic, hang or lose a byte.
License
Licensed under either of MIT or Apache-2.0, at your option. The tokenizer and parser follow Godot's, which is MIT-licensed (Godot's license).