LangStudies/App/RDP/Scripts/RDP_Viewer.gd

57 lines
1.3 KiB
GDScript3
Raw Normal View History

2022-07-14 14:12:25 -07:00
extends Panel
2022-07-23 23:56:37 -07:00
var Lexer = preload("RDP_Lexer.gd").new()
var Parser = preload("RDP_Parser.gd").new()
2022-07-14 14:12:25 -07:00
onready var Tokens_TOut = get_node("Tokens_TOut")
onready var AST_TOut = get_node("AST_TOut")
onready var FDialog = get_node("Letter_FDialog")
2022-07-14 14:45:24 -07:00
onready var FD_Btn = get_node("VBox/ParseLetterFile_Btn")
onready var Back_Btn = get_node("VBox/Back_Btn")
2022-07-14 14:12:25 -07:00
func tokens_out(text):
Tokens_TOut.insert_text_at_cursor(text)
func ast_out(text):
AST_TOut.insert_text_at_cursor(text)
func parse_file(path):
var \
file = File.new()
file.open(path, File.READ)
var programDescription = file.get_as_text()
file.close()
Lexer.init(programDescription)
for token in Lexer.Tokens :
var string = "[" + token.Type + "] " + token.Value + "\n"
tokens_out( string )
var ast = Parser.parse(Lexer)
var json = JSON.print(ast.to_Dictionary(), '\t')
ast_out(json + "\n")
ast_out("Finished Parsing!\n")
func fd_btn_pressed():
FDialog.popup()
func fdialog_FSelected(path):
Tokens_TOut.text = ""
AST_TOut.text = ""
parse_file(path)
func backBtn_pressed():
queue_free()
# Called when the node enters the scene tree for the first time.
func _ready():
FDialog.connect("file_selected", self, "fdialog_FSelected")
FD_Btn.connect("pressed", self, "fd_btn_pressed")
Back_Btn.connect("pressed", self, "backBtn_pressed")