From f3eb6685b2a9160d5294c7290b45d3eb90c84b00 Mon Sep 17 00:00:00 2001 From: lambda-abstraction <41861454+lambda-abstraction@users.noreply.github.com> Date: Wed, 18 Dec 2024 00:44:06 +0300 Subject: [PATCH] Fix whitespace regex replacement and file encoding (#11) * fix: py2gyat whitespace in regex * use utf-8 encoding --- pygyat/parser.py | 6 +++--- scripts/py2gyat | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pygyat/parser.py b/pygyat/parser.py index 45d3905..3f4a244 100644 --- a/pygyat/parser.py +++ b/pygyat/parser.py @@ -59,7 +59,7 @@ def parse_glazes(filename): list of str: All imported modules, suffixed with '.gyat'. Ie, the name the imported files must have if they are pygyat files. """ - infile = open(filename, "r") + infile = open(filename, "r", encoding="utf-8") infile_str = "" for line in infile: @@ -119,8 +119,8 @@ def parse_file(filepath, filename_prefix, outputname=None, change_imports=None): """ filename = os.path.basename(filepath) - infile = open(filepath, "r") - outfile = open(filename_prefix + _change_file_name(filename, outputname), "w") + infile = open(filepath, "r", encoding="utf-8") + outfile = open(filename_prefix + _change_file_name(filename, outputname), "w", encoding="utf-8") # Read file to string infile_str_raw = "" diff --git a/scripts/py2gyat b/scripts/py2gyat index f5ada0d..f3145c2 100644 --- a/scripts/py2gyat +++ b/scripts/py2gyat @@ -155,7 +155,7 @@ def reverse_parse(filename, outputname): outputname (str): Path of destination file """ # Open a file as bytes - infile = open(filename, "r") + infile = open(filename, "r", encoding="utf-8") inlines = infile.readlines() # Read file to string @@ -191,7 +191,7 @@ def reverse_parse(filename, outputname): # replace anything in mappings.keys() with its value but opposite for value, key in GYAT2PY_MAPPINGS.items(): if "\\s" in value: - value = value.replace("\\s", "s") + value = value.replace("\\s+", " ") line = safe_substitute(value, key, line) line = re.sub( r'(?