test
This commit is contained in:
@@ -6,7 +6,10 @@ datei_endung = ".png"
|
||||
|
||||
img = None
|
||||
output_img = None
|
||||
_bkp_font = ImageFont.truetype("res/fonts/NotoSans-Regular.ttf", 12) #in case set_font does funky stuff, backup the original font
|
||||
|
||||
_bkp_font = ImageFont.load_default()
|
||||
|
||||
#in case set_font does funky stuff, backup the original font
|
||||
font = _bkp_font
|
||||
|
||||
|
||||
@@ -77,7 +80,7 @@ def draw_if_statement(condition: str, x: int, y: int, true_sz: int, false_sz: in
|
||||
return x, y + text_y_size, true_sz, ysize - text_y_size, x + true_sz, y + text_y_size, false_sz, ysize - text_y_size
|
||||
|
||||
def draw_while_loop_front(condition: str, x: int, y: int, xsize: int, ysize: int):
|
||||
|
||||
|
||||
if not output_img:
|
||||
raise Exception("Output image was not initialized! Make sure to call NSD_init first")
|
||||
|
||||
@@ -98,7 +101,7 @@ def draw_while_loop_front(condition: str, x: int, y: int, xsize: int, ysize: int
|
||||
return x + xsize * .1, y + text_y_sz, xsize * .9
|
||||
|
||||
def draw_while_loop_back(condition: str, x: int, y: int, xsize: int, ysize: int):
|
||||
|
||||
|
||||
if not output_img:
|
||||
raise Exception("Output image was not initialized! Make sure to call NSD_init first")
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ class JavaInterpreter:
|
||||
def _get_scope_start_offset(self, i: int) -> int:
|
||||
if self._check_src(i, "{"):
|
||||
return 1
|
||||
elif self._check_src(i+1, "{"):
|
||||
elif self._check_src(i+1, "{"):
|
||||
return 2
|
||||
raise ScopeNotFoundException("Unable to find scope start. Is the program ill-formed?")
|
||||
|
||||
@@ -128,7 +128,7 @@ class JavaInterpreter:
|
||||
instruction_txt = line[6:bracket_idx]
|
||||
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)
|
||||
@@ -144,7 +144,7 @@ class JavaInterpreter:
|
||||
else:
|
||||
logging.debug("found else construct in line: %i", idx+1)
|
||||
instructions, idx = self._get_subscope(idx)
|
||||
|
||||
|
||||
elif self._check_line_start(idx+1, "else"):
|
||||
if self._check_src(idx+1, "if("):
|
||||
logging.debug("found else if construct in line: %i", idx+2)
|
||||
@@ -155,7 +155,7 @@ class JavaInterpreter:
|
||||
logging.debug("found else construct in line: %i", idx+2)
|
||||
instructions, idx = self._get_subscope(idx+1)
|
||||
return instructions, idx
|
||||
|
||||
|
||||
|
||||
def _handle_if(self, line: str, idx: int):
|
||||
bracket_idx = line.rindex(')') # throws if the contruct is illformed
|
||||
@@ -164,7 +164,7 @@ class JavaInterpreter:
|
||||
true_instructions, idx = self._get_subscope(idx)
|
||||
|
||||
false_instructions, idx = self._get_else_scope(idx)
|
||||
|
||||
|
||||
return if_instruction(instruction_txt, true_instructions, false_instructions), idx
|
||||
|
||||
def _handle_do_while(self, line: str, idx: int):
|
||||
@@ -193,7 +193,7 @@ class JavaInterpreter:
|
||||
var = segments[0][4:]
|
||||
cond = segments[1]
|
||||
inc = segments[2][:-2]
|
||||
|
||||
|
||||
instructions = []
|
||||
|
||||
if cond == "": #did you know test expressions where optional and defaulted to true? Me neither
|
||||
@@ -202,16 +202,16 @@ class JavaInterpreter:
|
||||
if var != "":
|
||||
variable_instruction = self._handle_variable(var, idx)[0]
|
||||
instructions.append(variable_instruction)
|
||||
|
||||
|
||||
brace_offset = self._get_scope_start_offset(idx)
|
||||
child_instructions, idx = self._get_instructions_in_scope(idx+brace_offset)
|
||||
|
||||
|
||||
if inc != "":
|
||||
increment_instruction = generic_instruction(inc)
|
||||
child_instructions.append(increment_instruction)
|
||||
|
||||
instructions.append(for_instruction("while " + cond, child_instructions))
|
||||
|
||||
|
||||
return instructions, idx
|
||||
|
||||
except IndexError:
|
||||
@@ -232,7 +232,7 @@ class JavaInterpreter:
|
||||
if line.startswith("while("):
|
||||
logging.debug("Found while construct in line: %i", idx+1)
|
||||
return self._handle_while(line, idx)
|
||||
|
||||
|
||||
elif line.startswith("if("):
|
||||
logging.debug("Found if construct in line: %i", idx+1)
|
||||
return self._handle_if(line, idx)
|
||||
@@ -258,7 +258,7 @@ class JavaInterpreter:
|
||||
i = idx
|
||||
while i < len(self._lines):
|
||||
line = self._lines[i]
|
||||
|
||||
|
||||
if self._check_src(i, '}'):
|
||||
break
|
||||
|
||||
@@ -270,7 +270,7 @@ class JavaInterpreter:
|
||||
|
||||
i += 1
|
||||
return scope, i
|
||||
|
||||
|
||||
def _remove_keywords(self):
|
||||
self.src = self._src.replace(' ', '')
|
||||
self.src = self._comment_pattern.sub('', self.src)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Optional
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import FileField, SubmitField
|
||||
from wtforms.validators import Optional
|
||||
from flask_wtf.file import FileAllowed
|
||||
from wtforms.fields.core import StringField
|
||||
|
||||
|
||||
Reference in New Issue
Block a user