improved interpreter

This commit is contained in:
weckyy702
2021-01-17 11:35:43 +01:00
parent a47f2c06ac
commit 6460f57da7
2 changed files with 13 additions and 13 deletions

View File

@@ -30,7 +30,7 @@ class NassiShneidermanDiagram:
if debug: if debug:
logLevel = logging.DEBUG logLevel = logging.DEBUG
logging.basicConfig(level=logLevel) logging.basicConfig(force=True, level=logLevel)
@staticmethod @staticmethod
def set_font(font_filepath: str): def set_font(font_filepath: str):
@@ -38,11 +38,11 @@ class NassiShneidermanDiagram:
@staticmethod @staticmethod
def _save_scope(scope: Function_scope, output_path: str): 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() 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 x, y = 0, 0
for instruction in scope.contents: for instruction in scope:
x, y = instruction.to_image(x, y, x_size) x, y = instruction.to_image(x, y, x_size)
@staticmethod @staticmethod

View File

@@ -13,6 +13,7 @@ logging.warning("""Because the Interpreter is still WIP, some Java language feat
*foreach loops (will throw JavaSyntaxError) *foreach loops (will throw JavaSyntaxError)
*constructors (will be ignored) *constructors (will be ignored)
*switch statements *switch statements
*Generics
Please remove these features from the source code as they will result in incorrect behaviour""") Please remove these features from the source code as they will result in incorrect behaviour""")
class Function_scope(Iterable): class Function_scope(Iterable):
@@ -29,10 +30,10 @@ class Function_scope(Iterable):
return int(h) return int(h)
def get_width(self) -> int: def get_width(self) -> int:
w = 0.0 w = 200.0
for inst in self.contents: for inst in self.contents:
w = max(w, inst.getblkwidth()) w = max(w, inst.getblkwidth())
return int(max(200, w)) return int(w)
def __iter__(self): def __iter__(self):
return self.contents.__iter__() return self.contents.__iter__()
@@ -43,16 +44,15 @@ class JavaInterpreter:
with open(filepath) as file: with open(filepath) as file:
if not file.readable(): if not file.readable():
raise InterpreterException(f"Unable to read input file {filepath}") 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._lines = [] # to be filled in later
self._init_regex() self.reset_tags()
self._recompile_regex()
def reset_tags(self, additional_tags: Dict[str, List[str]]=None): 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} """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 comment tags is "comments"
the key for tags that should be ignored is "ignore" The key for tags that should be ignored is "ignore"
the key for additional type tags is "types" The key for additional type tags is "types"
""" """
if additional_tags: if additional_tags: