Is there a way to parse a GDscript code (string) in a way I could modify it and save it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hinasis

Lets say I have a GD file like this:

extends Node
var my_dict = {
    name="my_name"
}

I have done a project that opens a GD file, reads some content, and shows me it in a readable way in and LineEdit node, I’ll just use print() for the example.

A Button opens a FileDialog then when a GD file is selected, it creates a Fileopening it for READ_WRITE and saving it in a variable named content as File.get_as_text().

func on_button_pressed():
    file_dialog.popup()
    file_dialog.connect("file_selected",self,"on_file_selected",[],CONNECT_ONESHOT)

func on_file_selected(path):
    var file = File.new()
    file.open(path,File.READ_WRITE)
    var content = file.get_as_text()
    read_content(content)

So then, it creates a GDScript named script, sets its source_codeas content and finaly reload().
After that it creates a Node, doing script.new()
Finally I just do print(my_node.my_dict.name) and all work as expected.

func read_content(content):
    var script = GDScript.new()
    script.source_code = content
    script.reload()
    var my_node = script.new()
    print(my_node.my_dict.name)

The next step is the problem, I can’t figure out how to modify the original script trying to avoid tedious tricks using all the String’s repertoire…
I would be nice to have access to a class/ GD file’s methods and members in a simple way like you do with json files, for example.
Is there something I’ve missed? Or do I have to program a code text editor?

After reading the file, I need to be able to modify it, visualy, in LineEdit nodes, and then save it, it doesn’t matter if it overwrites the original or not.

Thanks.