Skip to content

GDShrapt - C# libraries for parsing, validating, linting, and formatting GDScript code.

License

Notifications You must be signed in to change notification settings

elamaunt/GDShrapt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GDShrapt

NuGet License: MIT Tests Ko-fi

GDShrapt is a set of C# libraries for working with GDScript code — the scripting language of Godot Engine. Whether you need to parse, analyze, transform, validate, lint, or format GDScript source code, GDShrapt provides the building blocks to do it programmatically.

The libraries are designed to be used together or independently: from a lightweight parser for simple code inspection to a full-featured toolkit for building IDE plugins, CLI tools, or custom language integrations.

Why GDShrapt?

Design Philosophy

  • One-pass parsing — High-performance character-by-character parsing with no backtracking. The parser processes input in a single pass, making it predictable and fast.

  • Format preservation — Comments, whitespace, and formatting are preserved in the AST. Round-trip your code through parse → modify → generate without losing structure.

  • Modular architecture — Use only what you need. The core parser has zero dependencies; validation, linting, and formatting are separate packages.

  • Full GDScript 4.x — Complete support for modern GDScript: lambdas, await, typed arrays/dictionaries, pattern matching, all annotations.

Who Is This For?

  • IDE/Editor plugins — Build language support, code completion, refactoring tools
  • CLI tools — Create linters, formatters, code generators for CI/CD pipelines
  • Language embedding — Integrate GDScript parsing into other technologies
  • Code analysis — Static analysis, metrics, documentation generation

Packages

Package Description NuGet
GDShrapt.Reader Core parser and AST NuGet
GDShrapt.Builder Fluent API for code generation NuGet
GDShrapt.Validator AST validation with diagnostics NuGet
GDShrapt.Linter Style checking and naming conventions NuGet
GDShrapt.Formatter Code formatting with type inference NuGet

Installation

dotnet add package GDShrapt.Reader

Add optional packages as needed:

dotnet add package GDShrapt.Builder
dotnet add package GDShrapt.Validator
dotnet add package GDShrapt.Linter
dotnet add package GDShrapt.Formatter

Quick Start

Parse GDScript

using GDShrapt.Reader;

var reader = new GDScriptReader();
var tree = reader.ParseFileContent(@"
extends Node2D

@export var health: int = 100

func _ready():
    print(""Hello, Godot 4!"")
");

Console.WriteLine(tree.Extends?.Type);             // "Node2D"
Console.WriteLine(tree.Variables.First().Identifier); // "health"

Build GDScript

var classDecl = GD.Declaration.Class(
    GD.Atribute.Extends("Node2D"),
    GD.Declaration.Variable("speed", "float", GD.Expression.Number(100.0))
);
classDecl.UpdateIntendation();
Console.WriteLine(classDecl.ToString());

Validate

var validator = new GDValidator();
var result = validator.Validate(tree);

foreach (var error in result.Errors)
    Console.WriteLine(error); // "error GD5001: 'break' can only be used inside a loop (3:4)"

Lint

var linter = new GDLinter();
var result = linter.LintCode(code);

foreach (var issue in result.Issues)
    Console.WriteLine(issue); // "warning GDL101: Variable 'MyVar' should use snake_case (2:4)"

Format

var formatter = new GDFormatter();
var formatted = formatter.FormatCode(code);
// Applies consistent spacing, indentation, and line endings

Documentation

Each package has detailed documentation in its README:

For examples, see the test projects in src/.

Changelog

See CHANGELOG.md for version history.

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Support

If GDShrapt helps your project, consider supporting its development:

Ko-fi

Your support helps maintain these tools and build new features for the Godot community.

Ecosystem

Related projects:

Project Description
GDShrapt.TypesMap Runtime type provider for Godot classes and global functions

License

This project is licensed under the MIT License — see the LICENSE file for details.

Acknowledgments

  • Godot Engine team for the amazing game engine
  • All contributors who have helped improve this project