This commit is contained in:
oleting
2020-12-30 16:33:07 +01:00
5 changed files with 32 additions and 20 deletions

2
.vscode/launch.json vendored
View File

@@ -8,7 +8,7 @@
"name": "Python: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "run.py",
"program": "debug.py",
"console": "integratedTerminal"
}
]

View File

@@ -83,6 +83,7 @@ class Gui:
[
sg.Text('Output name'),
sg.In(size=(25, 1), enable_events=True, key='-OUTPUT NAME-'),
sg.Button('Confirm', key='-SET OUTPUT NAME-'),
],
[
sg.HSeparator(),
@@ -211,10 +212,10 @@ class Gui:
'You didn\'t set a name for the image, it will be named randomly.')
output_name = secrets.token_hex(16)
folder = nassi(input_path=file_path, output_path=output_path, outputname=output_name, gui=self,
nassi(input_path=file_path, output_path=output_path, outputname=output_name, gui=self,
font_filepath=font_filepath, behaviour=exists_choice)
fnames = output(folder=folder)
fnames = output(values)
sg.popup_annoying('Successfully created!', title='Created',
auto_close_duration=2, auto_close=True, text_color='green')
window['-OUTPUT FILE LIST-'].update(fnames)
@@ -270,7 +271,7 @@ class Gui:
if event == '-OUTPUT FOLDER-':
logging.debug(('event = ' + str(event) +
' value = ' + str(values['-OUTPUT FOLDER-'])))
fnames = output(values['-OUTPUT FOLDER-'])
fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames)
elif event == '-OUTPUT FILE LIST-':
logging.debug(('event = ' + str(event) +
@@ -299,7 +300,7 @@ class Gui:
# optional Input
if event == '-OUTPUT NAME-':
if event == '-SET OUTPUT NAME-':
output_name = values['-OUTPUT NAME-']
if event == '-TTF FOLDER-':
@@ -313,7 +314,7 @@ class Gui:
if event == '-REFRESH-':
try:
fnames = output(values['-OUTPUT FOLDER-'])
fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames)
except NoPathError:
pass

View File

@@ -1,10 +1,9 @@
import os
from typing import Optional
from errors.custom import NoPathError
from interpreter.NassiShneidermann import NassiShneidermanDiagram, Overwrite_behaviour, OB
from typing import Optional
import os
import logging
from draw.Iinstruction import *
def nassi(input_path: str, output_path: str, outputname: str, gui, behaviour: Overwrite_behaviour, font_filepath: Optional[str]=None):
NSD = NassiShneidermanDiagram(gui.debug_mode)
@@ -27,12 +26,9 @@ def nassi(input_path: str, output_path: str, outputname: str, gui, behaviour: Ov
return output_directory
def output(folder):
if folder:
output_path = folder
else:
raise
def output(values):
output_path = values['-OUTPUT FOLDER-']
if output_path == '':
raise NoPathError
try:

View File

@@ -19,10 +19,16 @@ class Function_scope(Iterable):
self.return_type = return_type
self.args = args
def get_height(self) -> int:
h = 0.0
for inst in self.contents:
h += inst.getblksize()
return int(h)
def __iter__(self):
return self.contents.__iter__()
COMMENT_PATTERN = re.compile(r"""^//|^/\*\*|^\*|^--""")
COMMENT_PATTERN = re.compile(r"""^(//|--|#).*""")
REMOVE_KEYWORDS = [' ', ';', "public", "private", "final", "protected"]
VARIABLE_TAGS = ["byte", "short", "int", "long", "float", "double", "boolean", "char", "String"]
FUNCTION_IDENTIFIERS = ["void"]
@@ -31,13 +37,12 @@ FUNCTION_IDENTIFIERS.extend(VARIABLE_TAGS)
WHILE_TAG = "solange " #german for 'while'. Change this depending on your language
REPLACE = dict((re.escape(k), '') for k in REMOVE_KEYWORDS)
remove_pattern = re.compile("|".join(REPLACE.keys()))
remove_pattern = re.compile("|".join(REPLACE.keys()), flags=re.MULTILINE)
variable_regex = "^("
for kw in VARIABLE_TAGS:
variable_regex += fr"""{kw}|"""
variable_pattern = re.compile(variable_regex[0:-1]+")(.*=|.*;)(.*)")
print(variable_pattern)
variable_pattern = re.compile(variable_regex[0:-1]+")(.*)=?(.*)", flags=re.MULTILINE)
function_regex = "^("
for kw in FUNCTION_IDENTIFIERS:
@@ -173,6 +178,7 @@ def handle_instruction(line: str, src: List[str], i: int) -> Tuple[Iinstruction,
elif variable_pattern.match(line):
logging.debug("Found variable in line %i", i+1)
print("found variable in line ", i+1)
return handle_variable(line, src, i)
else:
@@ -224,6 +230,13 @@ def get_function_scopes(src: List[str]) -> List[Function_scope]:
i+=1
return functions
def remove_keywords(src: str) -> str:
without_comments = ""
for line in src.splitlines(True):
if line != "\n" and not COMMENT_PATTERN.match(line):
without_comments += line
return remove_pattern.sub('', without_comments)
def load_scoped_instructions(filepath: str) -> List[Function_scope]:
src = load_src(filepath)
return get_function_scopes(src)

View File

@@ -1,5 +1,7 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
//Comment that the interpreter may never know of
public class Rover extends Actor
{
private Display anzeige;