From 6460f57da7ce4a3aef12f41c692efb6d927f9145 Mon Sep 17 00:00:00 2001 From: weckyy702 Date: Sun, 17 Jan 2021 11:35:43 +0100 Subject: [PATCH] improved interpreter --- interpreter/NassiShneidermann.py | 8 ++++---- interpreter/interpret_source.py | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/interpreter/NassiShneidermann.py b/interpreter/NassiShneidermann.py index a4612d2..fdb51de 100644 --- a/interpreter/NassiShneidermann.py +++ b/interpreter/NassiShneidermann.py @@ -30,7 +30,7 @@ class NassiShneidermanDiagram: if debug: logLevel = logging.DEBUG - logging.basicConfig(level=logLevel) + logging.basicConfig(force=True, level=logLevel) @staticmethod def set_font(font_filepath: str): @@ -38,11 +38,11 @@ class NassiShneidermanDiagram: @staticmethod def _save_scope(scope: Function_scope, output_path: str): - image_y_sz = scope.get_height() + y_size = scope.get_height() x_size = scope.get_width() - with NSD_writer(output_path, x_size, image_y_sz): + with NSD_writer(output_path, x_size, y_size): x, y = 0, 0 - for instruction in scope.contents: + for instruction in scope: x, y = instruction.to_image(x, y, x_size) @staticmethod diff --git a/interpreter/interpret_source.py b/interpreter/interpret_source.py index dce5a6a..f419c17 100644 --- a/interpreter/interpret_source.py +++ b/interpreter/interpret_source.py @@ -13,6 +13,7 @@ logging.warning("""Because the Interpreter is still WIP, some Java language feat *foreach loops (will throw JavaSyntaxError) *constructors (will be ignored) *switch statements + *Generics Please remove these features from the source code as they will result in incorrect behaviour""") class Function_scope(Iterable): @@ -29,10 +30,10 @@ class Function_scope(Iterable): return int(h) def get_width(self) -> int: - w = 0.0 + w = 200.0 for inst in self.contents: w = max(w, inst.getblkwidth()) - return int(max(200, w)) + return int(w) def __iter__(self): return self.contents.__iter__() @@ -43,16 +44,15 @@ class JavaInterpreter: with open(filepath) as file: if not file.readable(): raise InterpreterException(f"Unable to read input file {filepath}") - self._src = file.read() + self._src = file.read() #WARNING: throws if file is too large self._lines = [] # to be filled in later - self._init_regex() - self._recompile_regex() + self.reset_tags() def reset_tags(self, additional_tags: Dict[str, List[str]]=None): - """Reset the Interpreters internal tags to include the new tags given in {additional_tags} - the key for comment tags is "comments" - the key for tags that should be ignored is "ignore" - the key for additional type tags is "types" + """Reset the Interpreters internal tags to include the new tags given in {additional_tags} or default. + The key for comment tags is "comments" + The key for tags that should be ignored is "ignore" + The key for additional type tags is "types" """ if additional_tags: