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", "name": "Python: Aktuelle Datei",
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"program": "run.py", "program": "debug.py",
"console": "integratedTerminal" "console": "integratedTerminal"
} }
] ]

View File

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

View File

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

View File

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

View File

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