###################################### # THE CORE FRAMEWORK # # MADE BY THE STAROPENSOURCE PROJECT # # AND CONTRIBUTERS (THANK YOU!) # # # # COPYRIGHT 2023 THE STAROPENSOURCE # # PROJECT AND CONTRIBUTERS # # # # LICENSED UNDER THE GNU GENERAL # # PUBLIC LICENSE VERSION 3 (ONLY) # ###################################### extends Node ## ## # ##### ##### #### ## # # # # # # # ## # # # # # # #### ## # ## # # # # ## # # ##### # #### ## The preprocessor is *very* undocumented at this point ## in time as it is a little bit complicated. We may document ## it in the future, but for now you have to read the source. ## ## - JeremyStarTM # CORE modules var core: Node = null var logger: Node = null # Enables/disables preprocessor functionality @export var enabled = true # Do not enable unless you exactly know what you are doing! # It will spam your log chock full of useless garbage! @export var diagnostic = false # Checks if logger is null func initialize() -> void: if core.protection_mode: return if logger == null: return logger.diag("CORE/preprocessor.gd","Preprocessor is ready.",false) # Parses tags func _newline(msg:String,prefix:String,pre_msg:String,post_msg:String,exclusion_filter:Array) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing newline tags",false) var prefix_space = prefix for exclusion in exclusion_filter: prefix_space = prefix_space.replace(exclusion,"") prefix_space = " ".repeat(prefix_space.length()) var msg_proc = prefix + pre_msg + msg.replace("",post_msg + "\n" + prefix_space + pre_msg) + post_msg if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed newline tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Parses and tags func _case_lower(msg:String) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing lowercase tags",false) var msg_proc = msg while true: var index_one = msg_proc.find("") var index_two = msg_proc.find("") if index_one != -1: if index_two != -1: index_two = index_two + 5 - index_one var index_proc = msg_proc.substr(index_one,index_two) msg_proc = msg_proc.replace(index_proc,index_proc.replace("","").replace("","").to_lower()) else: core.exception("Preprocessor","Failed parsing lowercase tags in message \"" + msg + "\" (missing end tag?)") msg_proc = msg break else: break if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed lowercase tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Parses and tags func _case_upper(msg:String) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing uppercase tags",false) var msg_proc = msg while true: var index_one = msg_proc.find("") var index_two = msg_proc.find("") if index_one != -1: if index_two != -1: index_two = index_two + 5 - index_one var index_proc = msg_proc.substr(index_one,index_two) msg_proc = msg_proc.replace(index_proc,index_proc.replace("","").replace("","").to_upper()) else: core.exception("Preprocessor","Failed parsing uppercase tags in message \"" + msg + "\" (missing end tag?)") msg_proc = msg break else: break if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed uppercase tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Parses and tags func _case_camelcase(msg:String) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing camelcase tags",false) var msg_proc = msg while true: var index_one = msg_proc.find("") var index_two = msg_proc.find("") if index_one != -1: if index_two != -1: index_two = index_two + 5 - index_one var index_proc = msg_proc.substr(index_one,index_two) msg_proc = msg_proc.replace(index_proc,index_proc.replace("","").replace("","").to_camel_case()) else: core.exception("Preprocessor","Failed parsing camelcase tags in message \"" + msg + "\" (missing end tag?)") msg_proc = msg break else: break if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed camelcase tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Parses and tags func _case_pascalcase(msg:String) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing pascalcase tags",false) var msg_proc = msg while true: var index_one = msg_proc.find("") var index_two = msg_proc.find("") if index_one != -1: if index_two != -1: index_two = index_two + 5 - index_one var index_proc = msg_proc.substr(index_one,index_two) msg_proc = msg_proc.replace(index_proc,index_proc.replace("","").replace("","").to_pascal_case()) else: core.exception("Preprocessor","Failed parsing pascalcase tags in message \"" + msg + "\" (missing end tag?)") msg_proc = msg break else: break if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed pascalcase tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Parses and tags func _case_snakecase(msg:String) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing snakecase tags",false) var msg_proc = msg while true: var index_one = msg_proc.find("") var index_two = msg_proc.find("") if index_one != -1: if index_two != -1: index_two = index_two + 5 - index_one var index_proc = msg_proc.substr(index_one,index_two) msg_proc = msg_proc.replace(index_proc,index_proc.replace("","").replace("","").to_snake_case()) else: core.exception("Preprocessor","Failed parsing snakecase tags in message \"" + msg + "\" (missing end tag?)") msg_proc = msg break else: break if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed snakecase tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Function calls to everything *case-related func _case(msg:String) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing casing tags",false) var msg_proc = _case_lower(msg) msg_proc = _case_upper(msg_proc) msg_proc = _case_camelcase(msg_proc) msg_proc = _case_pascalcase(msg_proc) msg_proc = _case_snakecase(msg_proc) if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed casing tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Replaces all escapes func _escapes(msg:String) -> String: if core.protection_mode: return "" if diagnostic:logger.diag("CORE/preprocessor.gd","Parsing escape tags",false) var msg_proc = msg.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") msg_proc = msg_proc.replace("","") if diagnostic: logger.diag("CORE/preprocessor.gd","Parsed escape tags. Transformed \"" + msg + "\" into \"" + msg_proc + "\"",false) return msg_proc # Checks for tag and if found stops processing func _noprocess(msg:String) -> bool: if core.protection_mode: return true if diagnostic: logger.diag("CORE/preprocessor.gd","Checking for noprocess tag", false) if msg.contains(""): return true return false # Executes all preprocessing functions and returns their combined work func process(msg:String,prefix:String = "",pre_msg:String = "",post_msg:String = "",exclusion_filter:Array = []) -> String: if core.protection_mode: return "" if diagnostic: logger.diag("CORE/preprocessor.gd","Call to process() recieved",false) if !enabled: if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing failed: Preprocessor is disabled",false) return msg if _noprocess(msg): if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing stopped: noprocess tag detected", false) return msg var msg_proc = _case(msg) msg_proc = _newline(msg_proc,prefix,pre_msg,post_msg,exclusion_filter) msg_proc = _escapes(msg_proc) if diagnostic: logger.diag("CORE/preprocessor.gd","Parsing complete", false) return msg_proc