diff --git a/.github/workflows/test_preprocessor.yml b/.github/workflows/test_preprocessor.yml index ec20067..8a73dec 100644 --- a/.github/workflows/test_preprocessor.yml +++ b/.github/workflows/test_preprocessor.yml @@ -2,7 +2,8 @@ name: Test Preprocessor on: [push, pull_request] env: - GODOT_EXECUTABLE: Godot_v${{ vars.GODOT_VERSION }}_linux.x86_64 + GODOT_VERSION: 4.1.3-stable + GODOT_EXECUTABLE: Godot_v${{ env.GODOT_VERSION }}_linux.x86_64 jobs: test-preprocessor: @@ -19,12 +20,12 @@ jobs: cache-name: cache-godot with: path: ./${{ env.GODOT_EXECUTABLE }} - key: ${{ runner.os }}-${{ env.cache-name }}-${{ vars.GODOT_VERSION }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.GODOT_VERSION }} - if: ${{ steps.cache-godot.outputs.cache-hit != 'true' }} name: Install Godot run: | - wget -q https://github.com/godotengine/godot-builds/releases/download/${{ vars.GODOT_VERSION }}/${{ env.GODOT_EXECUTABLE }}.zip + wget -q https://github.com/godotengine/godot-builds/releases/download/${{ env.GODOT_VERSION }}/${{ env.GODOT_EXECUTABLE }}.zip unzip ${{ env.GODOT_EXECUTABLE }}.zip - name: Run tests diff --git a/README.md b/README.md index d69d2a6..b1de285 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ An export plugin for stripping comments and "conditional compilation" of GDScript. -Compatible with Godot 4.2. +Compatible with Godot 4.1. ## How to use diff --git a/addons/gdscript_preprocessor/export_plugin.gd b/addons/gdscript_preprocessor/export_plugin.gd index e0adbc9..42e965a 100644 --- a/addons/gdscript_preprocessor/export_plugin.gd +++ b/addons/gdscript_preprocessor/export_plugin.gd @@ -1,7 +1,6 @@ extends EditorExportPlugin -@warning_ignore("inferred_declaration") const _Preprocessor = preload("./preprocessor.gd") var _config_path: String @@ -37,7 +36,7 @@ func _export_begin( regex = _get_option(config, "statements", "removing_regex_debug", "") else: regex = _get_option(config, "statements", "removing_regex_release", - r"^(?:breakpoint|assert\(|print_debug\(|print_stack\()") + "^(?:breakpoint|assert\\(|print_debug\\(|print_stack\\()") if not regex.is_empty(): _preprocessor.statement_removing_regex = RegEx.create_from_string(regex) if not _preprocessor.statement_removing_regex.is_valid(): diff --git a/addons/gdscript_preprocessor/plugin.gd b/addons/gdscript_preprocessor/plugin.gd index 501e4db..6bdf8f5 100644 --- a/addons/gdscript_preprocessor/plugin.gd +++ b/addons/gdscript_preprocessor/plugin.gd @@ -2,7 +2,6 @@ extends EditorPlugin -@warning_ignore("inferred_declaration") const _ExportPlugin = preload("./export_plugin.gd") var _export_plugin: _ExportPlugin = _ExportPlugin.new() diff --git a/addons/gdscript_preprocessor/preprocessor.gd b/addons/gdscript_preprocessor/preprocessor.gd index 08ba6a6..e82087a 100644 --- a/addons/gdscript_preprocessor/preprocessor.gd +++ b/addons/gdscript_preprocessor/preprocessor.gd @@ -29,7 +29,6 @@ const _PAREN_CLOSE: int = 0x0029 # ")" const _BRACKET_OPEN: int = 0x005B # "[" const _BACKSLASH: int = 0x005C # "\\" const _BRACKET_CLOSE: int = 0x005D # "]" -const _SMALL_R: int = 0x0072 # "r" const _BRACE_OPEN: int = 0x007B # "{" const _BRACE_CLOSE: int = 0x007D # "}" @@ -63,9 +62,9 @@ var _output_enabled: bool = true var _paren_stack: Array[int] var _os_has_feature_regex: RegEx = RegEx.create_from_string( - r"""OS\.has_feature\((["'])(\w+)\1\)""") + """OS\\.has_feature\\((["'])(\\w+)\\1\\)""") var _cond_regex: RegEx = RegEx.create_from_string( - r"^(false|true|and|or|not|&&|\|\||!|\(|\)| |\t|\r|\n)+$") + "^(false|true|and|or|not|&&|\\|\\||!|\\(|\\)| |\\t|\\r|\\n)+$") var _expression: Expression = Expression.new() @@ -187,17 +186,9 @@ func _parse_statement() -> void: return _position += 1 elif c == _QUOT or c == _APOS: - _parse_string(false) + _parse_string() if not error_message.is_empty(): return - elif c == _SMALL_R: - _position += 1 - if _position < _length: - var q: int = _source.unicode_at(_position) - if q == _QUOT or q == _APOS: - _parse_string(true) - if not error_message.is_empty(): - return elif c == _HASH: # Skip comment. string += _source.substr(from, _position - from) @@ -324,7 +315,7 @@ func _parse_statement() -> void: current_block.status = _Status.NORMAL -func _parse_string(is_raw: bool) -> void: +func _parse_string() -> void: var quote_char: int = _source.unicode_at(_position) _position += 1 @@ -346,15 +337,10 @@ func _parse_string(is_raw: bool) -> void: error_message = "Unterminated string." return var esc: int = _source.unicode_at(_position) - if is_raw: - if esc == quote_char or esc == _BACKSLASH: - _position += 1 - # else: **not** advance. - else: - # Let's assume the escape is valid. - _position += 1 - if esc == _NEWLINE: - _line += 1 + # Let's assume the escape is valid. + _position += 1 + if esc == _NEWLINE: + _line += 1 elif c == quote_char: _position += 1 if is_multiline: @@ -380,7 +366,7 @@ func _eval_cond(cond: String) -> _Trilean: .replace("OS.is_debug_build()", "true" if is_debug else "false") var matches: Array[RegExMatch] = _os_has_feature_regex.search_all(cond) - for i: int in range(matches.size() - 1, -1, -1): + for i in range(matches.size() - 1, -1, -1): var m: RegExMatch = matches[i] cond = cond.left(m.get_start()) + ("true" if features.has(m.get_string(2)) else "false") \ + cond.substr(m.get_end()) diff --git a/project.godot b/project.godot index 8a747f9..96f224c 100644 --- a/project.godot +++ b/project.godot @@ -11,14 +11,12 @@ config_version=5 [application] config/name="gdscript-preprocessor" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.1", "Forward Plus") config/icon="res://icon.png" [debug] gdscript/warnings/exclude_addons=false -gdscript/warnings/untyped_declaration=1 -gdscript/warnings/inferred_declaration=1 gdscript/warnings/unsafe_property_access=1 gdscript/warnings/unsafe_method_access=1 gdscript/warnings/unsafe_cast=1 diff --git a/test_runner.gd b/test_runner.gd index 3d0c197..35e740b 100644 --- a/test_runner.gd +++ b/test_runner.gd @@ -1,14 +1,13 @@ extends SceneTree -@warning_ignore("inferred_declaration") const _Preprocessor = preload("./addons/gdscript_preprocessor/preprocessor.gd") var _preprocessor: _Preprocessor = _Preprocessor.new() func _init() -> void: - for file_name: String in DirAccess.get_files_at("tests/"): + for file_name in DirAccess.get_files_at("tests/"): if not file_name.ends_with(".gd"): continue diff --git a/tests/strings.gd b/tests/strings.gd index a46a880..8fa10ab 100644 --- a/tests/strings.gd +++ b/tests/strings.gd @@ -4,30 +4,6 @@ func test() -> void: print("""test test \n \" ' '' " "" \\""") - # https://github.com/godotengine/godot/blob/master/ - # modules/gdscript/tests/scripts/parser/features/r_strings.gd - print(r"test ' \' \" \\ \n \t \u2023 test") - print(r"\n\\[\t ]*(\w+)") - print(r"") - print(r"\"") - print(r"\\\"") - print(r"\\") - print(r"\" \\\" \\\\\"") - print(r"\ \\ \\\ \\\\ \\\\\ \\") - print(r'"') - print(r'"(?:\\.|[^"])*"') - print(r"""""") - print(r"""test \t "test"="" " \" \\\" \ \\ \\\ test""") - print(r'''r"""test \t "test"="" " \" \\\" \ \\ \\\ test"""''') - print(r"\t - \t") - print(r"\t \ - \t") - print(r"""\t - \t""") - print(r"""\t \ - \t""") - if true: if false: print("test") diff --git a/tests/strings.txt b/tests/strings.txt index 7e9aac2..15f3684 100644 --- a/tests/strings.txt +++ b/tests/strings.txt @@ -4,26 +4,5 @@ func test() -> void: test \n \" ' '' \\") print("""test test \n \" ' '' " "" \\""") - print(r"test ' \' \" \\ \n \t \u2023 test") - print(r"\n\\[\t ]*(\w+)") - print(r"") - print(r"\"") - print(r"\\\"") - print(r"\\") - print(r"\" \\\" \\\\\"") - print(r"\ \\ \\\ \\\\ \\\\\ \\") - print(r'"') - print(r'"(?:\\.|[^"])*"') - print(r"""""") - print(r"""test \t "test"="" " \" \\\" \ \\ \\\ test""") - print(r'''r"""test \t "test"="" " \" \\\" \ \\ \\\ test"""''') - print(r"\t - \t") - print(r"\t \ - \t") - print(r"""\t - \t""") - print(r"""\t \ - \t""") if true: pass