GDShrapt.Validator provides compiler-style AST validation for GDScript 2.0 (Godot 4.x) with type inference. Diagnostic Categories: - Syntax (GD1xxx): Invalid tokens, missing brackets, unexpected tokens - Scope (GD2xxx): Undefined variables, duplicate declarations, forward references - Type (GD3xxx): Type mismatches, invalid operand types - Call (GD4xxx): Wrong argument counts for built-in functions - Control Flow (GD5xxx): break/continue outside loops, return outside functions - Indentation (GD6xxx): Mixed tabs/spaces, inconsistent indentation - Await (GD7xxx): Await expression structure issues Type Inference System: - IGDRuntimeProvider interface for custom type information (integrate with Godot) - GDDefaultRuntimeProvider with built-in GDScript types and global functions - GDCachingRuntimeProvider wrapper for performance optimization - GDTypeInferenceEngine for expression type inference - Two-pass validation with full forward reference support Usage: new GDValidator().Validate(tree, options) Requires: GDShrapt.Reader
$ dotnet add package GDShrapt.ValidatorCompiler-style AST validation for GDScript 2.0 (Godot 4.x) with type inference.
GDTypeInferenceEngineIGDRuntimeProvider| Category | Code | Description |
|---|---|---|
| Syntax | GD1xxx | Invalid tokens, missing brackets, unexpected tokens |
| Scope | GD2xxx | Undefined variables, duplicate declarations |
| Type | GD3xxx | Type mismatches, invalid operand types |
| Call | GD4xxx | Wrong argument counts for built-in functions |
| Control Flow | GD5xxx | break/continue outside loops, return outside functions |
| Indentation | GD6xxx | Mixed tabs/spaces, inconsistent indentation |
| Await | GD7xxx | Await expression structure issues |
using GDShrapt.Reader;
var reader = new GDScriptReader();
var code = @"
func test():
break # Error: break outside loop
print(undefined_var) # Error: undefined variable
";
var tree = reader.ParseFileContent(code);
var validator = new GDValidator();
var result = validator.Validate(tree);
if (!result.IsValid)
{
foreach (var error in result.Errors)
{
// Output: "error GD5001: 'break' can only be used inside a loop (3:4)"
Console.WriteLine(error.ToString());
}
}
var options = new GDValidationOptions
{
CheckSyntax = true, // GD1xxx errors
CheckScope = true, // GD2xxx errors
CheckTypes = true, // GD3xxx warnings
CheckCalls = true, // GD4xxx errors
CheckControlFlow = true, // GD5xxx errors
CheckIndentation = true, // GD6xxx warnings
CheckAwait = true // GD7xxx errors
};
var result = validator.Validate(tree, options);
Integrate with Godot's actual type system:
public class GodotRuntimeProvider : IGDRuntimeProvider
{
public bool IsKnownType(string typeName) => /* check Godot types */;
public GDRuntimeTypeInfo GetTypeInfo(string typeName) => /* return type info */;
// ... other methods
}
// Use with caching for performance
var provider = new GDCachingRuntimeProvider(new GodotRuntimeProvider());
var options = new GDValidationOptions { RuntimeProvider = provider };
var result = validator.Validate(tree, options);
| Package | Description |
|---|---|
| GDShrapt.Reader | Core parser and AST (required) |
| GDShrapt.Builder | Fluent API for code generation |
| GDShrapt.Linter | Style checking and naming conventions |
| GDShrapt.Formatter | Code formatting with type inference |
Full documentation and examples: GitHub Repository
MIT License - see LICENSE for details.