From 846232dbab1d0d73a838effe816bf56959347f36 Mon Sep 17 00:00:00 2001 From: JoBe <165585785+JoBeGaming@users.noreply.github.com> Date: Sat, 15 Aug 2026 13:08:33 -0600 Subject: [PATCH] Fix brainfuck error messages for `create_brace_map` function. See https://discord.com/channels/116914772766752769/1443380125197537387/1538262689086971914 and previous discussion a bit above that. --- brainfuck.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/brainfuck.py b/brainfuck.py index a181b40..60c5f88 100644 --- a/brainfuck.py +++ b/brainfuck.py @@ -20,21 +20,21 @@ def create_brace_map(code: str): stack.append(ptr) elif code[ptr] == "]": if not stack: - raise SyntaxError("Unmatched ']'") + raise SyntaxError(f"error: unmatched ']' at character {ptr}") opening_brace = stack.pop() brace_map[opening_brace] = ptr brace_map[ptr] = opening_brace ptr += 1 if stack: - raise SyntaxError(stack.pop()) + raise SyntaxError(f"error: unmatched '[' at character {stack.pop()}") return brace_map def process_brainfuck(code: str, input: str): memory = Memory(input) try: memory.brace_map = create_brace_map(code) - except SyntaxError as e: - return f"error: unmatched '[' at character {e.args[0]}" + except SyntaxError as err: + return err.args[0] memory.counter = 0 while memory.counter < len(code): match code[memory.counter]: @@ -73,4 +73,4 @@ def process_brainfuck(code: str, input: str): memory.loops_counter = 0 memory.counter += 1 - return memory.output \ No newline at end of file + return memory.output