diff --git a/ti842py/__version__.py b/ti842py/__version__.py index a05dc36..cd4fd78 100644 --- a/ti842py/__version__.py +++ b/ti842py/__version__.py @@ -1,7 +1,7 @@ __title__ = "ti842py" __description__ = "TI-BASIC to Python 3 Transpiler" __url__ = "https://github.com/TabulateJarl8/ti842py" -__version__ = "0.9.5" +__version__ = "0.9.6" __author__ = "Tabulate" __author_email__ = "tabulatejarl8@gmail.com" __license__ = "GPLv3" diff --git a/ti842py/parsing_utils.py b/ti842py/parsing_utils.py index b88352a..26e434c 100644 --- a/ti842py/parsing_utils.py +++ b/ti842py/parsing_utils.py @@ -207,3 +207,5 @@ def decistmt(s): # Convert token list back into source code return tokenize.untokenize(result).decode('utf-8') +def remove_values_from_list(lst, iterable): + return [item for item in lst if item.strip() not in iterable] \ No newline at end of file diff --git a/ti842py/tiParser.py b/ti842py/tiParser.py index dfa690d..a99ec1a 100644 --- a/ti842py/tiParser.py +++ b/ti842py/tiParser.py @@ -26,7 +26,7 @@ def __init__(self, basic, multiplication, floating_point, turbo_draw): self.turbo_draw = turbo_draw # Utility Functions - self.UTILS = {"wait": {"code": [""], "imports": ["import time"], "enabled": False}, "menu": {"code": [""], "imports": ["import dialog"], "enabled": False}, "math": {"code": [""], "imports": ["import math"], "enabled": False}, 'random': {'code': [''], 'imports': ['import random'], 'enabled': False}} + self.UTILS = {"wait": {"code": [""], "imports": ["import time"], "enabled": False}, "menu": {"code": [""], "imports": ["import dialog"], "enabled": False}, "math": {"code": [""], "imports": ["import math"], "enabled": False}, 'random': {'code': [''], 'imports': ['import random'], 'enabled': False}, 'traceback': {'code': [''], 'imports': ['import traceback'], 'enabled': True}} here = os.path.abspath(os.path.dirname(__file__)) for file in [file for file in os.listdir(os.path.join(here, "utils")) if os.path.isfile(os.path.join(here, "utils", file))]: with open(os.path.join(here, "utils", file)) as f: @@ -124,6 +124,13 @@ def convertLine(self, index, line): else: statement = "input()" self.UTILS["toNumber"]["enabled"] = True + + # stop listening for keyboard input on input + # these statements will be removed in post-processing if getKey isn't used + if not isinstance(statement, list): + statement = [statement] + statement.insert(0, 'listener.stop()') + statement.extend(['listener = pynput.keyboard.Listener(on_press=get_key.set_last_key)', 'listener.start()']) # For loop elif line.startswith("For"): args = line[4:].strip("()").split(",") @@ -165,6 +172,13 @@ def convertLine(self, index, line): statement = "input(" if len(args) == 1: statement += str(args[0]) + ")" + + # stop listening for keyboard input on input + # these statements will be removed in post-processing if getKey isn't used + if not isinstance(statement, list): + statement = [statement] + statement.insert(0, 'listener.stop()') + statement.extend(['listener = pynput.keyboard.Listener(on_press=get_key.set_last_key)', 'listener.start()']) else: statement = ["print(" + str(args[0]) + ")", "time.sleep(" + args[1] + ")"] self.UTILS["wait"]["enabled"] = True @@ -187,6 +201,13 @@ def convertLine(self, index, line): else: statement = variable + " = toNumber(input(\"" + variable + "=?\"))" self.UTILS["toNumber"]["enabled"] = True + + # stop listening for keyboard input on input + # these statements will be removed in post-processing if getKey isn't used + if not isinstance(statement, list): + statement = [statement] + statement.insert(0, 'listener.stop()') + statement.extend(['listener = pynput.keyboard.Listener(on_press=get_key.set_last_key)', 'listener.start()']) # Goto (eww) elif line.startswith("Goto "): statement = "goto .lbl" + line[5:] @@ -362,13 +383,13 @@ def convertLine(self, index, line): if re.search(r'l[1-6]\([0-9A-Za-z]+\)', ' '.join(statement)): # List subscription try: - statement = parsing_utils.noStringReplace(r'(l[1-6])\(([0-9A-Za-z]+)\)', lambda m: m.group(1) + '[' + str(int(m.group(2)) - 1) + ']', statement) + statement = parsing_utils.noStringReplace(r'(l[1-6])\(([0-9A-Z]+)\)', lambda m: m.group(1) + '[' + str(int(m.group(2)) - 1) + ']', statement) except ValueError: - statement = parsing_utils.noStringReplace(r'(l[1-6])\(([0-9A-Za-z]+)\)', lambda m: m.group(1) + '[' + m.group(2) + ']', statement) + statement = parsing_utils.noStringReplace(r'(l[1-6])\(([0-9A-Z]+)\)', lambda m: m.group(1) + '[' + m.group(2) + ']', statement) if re.search(r'\[[A-J]\]', ' '.join(statement)): # Matrices - statement = parsing_utils.noStringReplace(r'\[([A-J])\]', r'matrix_\1', statement) + statement = parsing_utils.noStringReplace(r'(?