Skip to content

GDShrapt is object-oriented one-pass parser of GDScript and one-pass converter to C#. The project written in C# and consists of two parts. GDShrapt.Reader to build a lexical tree or generate a new code from scratch. GDShrapt.Converter to convert lexical tree in same C# code.

License

Notifications You must be signed in to change notification settings

galievaL/GDShrapt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GDShrapt

GDShrapt is object-oriented one-pass parser of GDScript. Also it allows to convert code to C#. The project written in C#, consists of two parts GDShrapt.Reader and GDShrapt.Converter and free to use. GDScript is the main language of Godot Engine

GDShrapt.Reader

GDShrapt.Reader allows to build a lexical tree or generate a new code from scratch.

How to install

Currently available prealpha version from Nuget.

Installation from Nuget console:

Install-Package GDShrapt.Reader -Version 1.0.0-prealpha

Samples

GDScript input:

tool
class_name HTerrainDataSaver
extends ResourceFormatSaver

const HTerrainData = preload("./ hterrain_data.gd")


func get_recognized_extensions(res):
	if res != null and res is HTerrainData:
		return PoolStringArray([HTerrainData.META_EXTENSION])
	return PoolStringArray()


func recognize(res):
	return res is HTerrainData


func save(path, resource, flags):
	resource.save_data(path.get_base_dir())

Parser usage:

 // Initialize a reader instance
 var reader = new GDScriptReader();
 
 // Parse the raw code
 var @class = reader.ParseFileContent(code); // returns instance of type GDClassDeclaration 
 
 // Get 'extends' atribute information
 Console.WriteLine(@class.Extends.Type.Sequence); // outputs base class name "ResourceFormatSaver"
 
 // Get 'class_name' atribute information
 Console.WriteLine(@class.ClassName.Type.Sequence); // outputs current class name "HTerrainDataSaver"
 
 // Check 'tool' atribute 
 Console.WriteLine(@class.IsTool); // outputs true 
 
 // Enumerates all class variables
 foreach(GDVariableDeclaration variable in @class.Variables)
 {
    Console.WriteLine(method.Identifier.Sequence); // outputs variables's name
 }
 
 // Enumerates all class methods
 foreach(GDMethodDeclaration method in @class.Methods)
 {
    Console.WriteLine(method.Identifier.Sequence); // outputs method's name
    
    // Enumerates all method statements
    foreach(GDStatement st in method.Statements)
    {
        // ... your code
    }
 }

Tree building samples and runtime code generation are coming soon. For more samples see the tests.

GDShrapt.Converter

GDShrapt.Converter allows to convert lexical tree in same C# code. This project is at very initial stage.

Samples

Not ready.

Current state

The project is in pre-pre-alpha stage. The reader has some specific limitations on parsing 'match' statements. It will be parsed but without specific node types. It may be not convenient to handle this nodes by code.

Current goals

Complete parsing of GDScript without limitations.

About

GDShrapt is object-oriented one-pass parser of GDScript and one-pass converter to C#. The project written in C# and consists of two parts. GDShrapt.Reader to build a lexical tree or generate a new code from scratch. GDShrapt.Converter to convert lexical tree in same C# code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%