From 4991b0c6b5f86f72ac0de4a37f58fe4e8a3ec7a7 Mon Sep 17 00:00:00 2001 From: weckyy702 Date: Sun, 17 Jan 2021 12:25:41 +0100 Subject: [PATCH] small cleanups --- interpreter/interpret_source.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/interpreter/interpret_source.py b/interpreter/interpret_source.py index 35d25fb..e0516f8 100644 --- a/interpreter/interpret_source.py +++ b/interpreter/interpret_source.py @@ -1,6 +1,5 @@ import logging import re -import sys from typing import Dict, List, Match, Tuple, Union from errors.custom import InterpreterException, JavaSyntaxError, ScopeNotFoundException @@ -122,6 +121,10 @@ class JavaInterpreter: return 2 raise ScopeNotFoundException("Unable to find scope start. Is the program ill-formed?") + def _get_subscope(self, idx: int): + brace_offset = self._get_scope_start_offset(idx) + return self._get_instructions_in_scope(idx+brace_offset) + def _handle_while(self, line: str, idx: int): bracket_idx = line.rindex(')') # throws if while contruct is illformed @@ -129,10 +132,6 @@ class JavaInterpreter: child_instructions, idx = self._get_subscope(idx) return while_instruction_front(("while" + instruction_txt), child_instructions), idx - def _get_subscope(self, idx: int): - brace_offset = self._get_scope_start_offset(idx) - return self._get_instructions_in_scope(idx+brace_offset) - def _get_else_scope(self, idx:int): instructions = None if self._check_line_start(idx, "}else"): @@ -289,7 +288,7 @@ class JavaInterpreter: brace_offset = self._get_scope_start_offset(idx) return self._get_instructions_in_scope(idx+brace_offset)[0] - def _get_function_scope(self, match: re.Match[str]): + def _get_function_scope(self, match: Match[str]): span = match.span() header = self.src[span[0]:span[1]].replace('\n', '')