# # BSD 3-Clause License # # Copyright (c) 2018 - 2023, Oleg Malyavkin # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # * Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. extends Node const PROTO_VERSION_CONST : String = "const PROTO_VERSION = " const PROTO_VERSION_DEFAULT : String = PROTO_VERSION_CONST + "0" class Document: func _init(doc_name : String, doc_text : String): name = doc_name text = doc_text var name : String var text : String class TokenPosition: func _init(b : int, e : int): begin = b end = e var begin : int = 0 var end : int = 0 class Helper: class StringPosition: func _init(s : int, c : int, l : int): str_num = s column = c length = l var str_num : int var column : int var length : int static func str_pos(text : String, position : TokenPosition) -> StringPosition: var cur_str : int = 1 var cur_col : int = 1 var res_str : int = 0 var res_col : int = 0 var res_length : int = 0 for i in range(text.length()): if text[i] == "\n": cur_str += 1 cur_col = 0 if position.begin == i: res_str = cur_str res_col = cur_col res_length = position.end - position.begin + 1 break cur_col += 1 return StringPosition.new(res_str, res_col, res_length) static func text_pos(tokens : Array, index : int) -> TokenPosition: var res_begin : int = 0 var res_end : int = 0 if index < tokens.size() && index >= 0: res_begin = tokens[index].position.begin res_end = tokens[index].position.end return TokenPosition.new(res_begin, res_end) static func error_string(file_name, col, row, error_text): return file_name + ":" + str(col) + ":" + str(row) + ": error: " + error_text class AnalyzeResult: var classes : Array = [] var fields : Array = [] var groups : Array = [] var version : int = 0 var state : bool = false var tokens : Array = [] var syntax : Analysis.TranslationResult var imports : Array = [] var doc : Document func soft_copy() -> AnalyzeResult: var res : AnalyzeResult = AnalyzeResult.new() res.classes = classes res.fields = fields res.groups = groups res.version = version res.state = state res.tokens = tokens res.syntax = syntax res.imports = imports res.doc = doc return res class Analysis: func _init(path : String, doc : Document): path_dir = path document = doc var document : Document var path_dir : String const LEX = { LETTER = "[A-Za-z]", DIGIT_DEC = "[0-9]", DIGIT_OCT = "[0-7]", DIGIT_HEX = "[0-9]|[A-F]|[a-f]", BRACKET_ROUND_LEFT = "\\(", BRACKET_ROUND_RIGHT = "\\)", BRACKET_CURLY_LEFT = "\\{", BRACKET_CURLY_RIGHT = "\\}", BRACKET_SQUARE_LEFT = "\\[", BRACKET_SQUARE_RIGHT = "\\]", BRACKET_ANGLE_LEFT = "\\<", BRACKET_ANGLE_RIGHT = "\\>", SEMICOLON = ";", COMMA = ",", EQUAL = "=", SIGN = "\\+|\\-", SPACE = "\\s", QUOTE_SINGLE = "'", QUOTE_DOUBLE = "\"", } const TOKEN_IDENT :
name: "Mastery Room"
masteries {
name: "MASTERY"
path: "Components/Collectables/smiley"
}