changed logic

another_parse_input
a.jurcenko 2025-09-20 13:14:17 +02:00
parent b5584bf316
commit d608d2f077
2 changed files with 19 additions and 9 deletions

View File

@ -43,10 +43,14 @@ class AbacusCore:
:param input_str: :param input_str:
:return: :return:
''' '''
input_str = input_str.strip()
comment = None comment = None
orig_input_str = input_str orig_input_str = input_str
if len(input_str) < 1: # leere eingabe wird nicht akzeptiert if len(input_str) < 1: # leere eingabe wird nicht akzeptiert
return return
if input_str[0] == '#': # ganze eingabe ist ein kommentar
comment = input_str
return None, None, None, comment
chunks = input_str.split('#') chunks = input_str.split('#')
if len(chunks) > 1: if len(chunks) > 1:
input_str = chunks[0] input_str = chunks[0]
@ -56,6 +60,7 @@ class AbacusCore:
raise ValueError('Mehrfachzuweisung wird nicht unterstützt') raise ValueError('Mehrfachzuweisung wird nicht unterstützt')
elif len(chunks) > 1: elif len(chunks) > 1:
expression = self._with_variable_another_way(chunks[1]) expression = self._with_variable_another_way(chunks[1])
chunks[0] = '_'.join(chunks[0].strip().split(' '))
self._vars[chunks[0]] = expression self._vars[chunks[0]] = expression
return return
chunks = input_str.split(':') # gibt es funktionsdefinition? chunks = input_str.split(':') # gibt es funktionsdefinition?

23
main.py
View File

@ -39,7 +39,6 @@ class AbacusGUI:
sys.exit(self._app.exec()) sys.exit(self._app.exec())
def _berechne(self): def _berechne(self):
self._step += 1
input_str = self._window.le_input.text() input_str = self._window.le_input.text()
result = self._abacus_core.parse_input(input_str) result = self._abacus_core.parse_input(input_str)
if result: if result:
@ -48,14 +47,20 @@ class AbacusGUI:
input_wo_var = str(result[1]) input_wo_var = str(result[1])
ergebnis = str(result[2]) ergebnis = str(result[2])
comment = result[3] comment = result[3]
res_str = str(self._step) + '. ' + input_str + ' = ' + ergebnis if result[0] is not None:
# res_str = str(self._step) + '. ' + input_str + ' => ' + input_wo_var + ' = ' + ergebnis self._step += 1
if comment: res_str = str(self._step) + '> ' + input_str + ' = ' + ergebnis
res_str += ' ' + comment # res_str = str(self._step) + '. ' + input_str + ' => ' + input_wo_var + ' = ' + ergebnis
item = QStandardItem(res_str) if comment:
self._history_model.appendRow(item) res_str += ' ' + comment
res = result[2] item = QStandardItem(res_str)
self._window.le_input.setText(str(res)) self._history_model.appendRow(item)
res = result[2]
self._window.le_input.setText(str(res))
elif result[3] is not None:
item = QStandardItem(comment)
self._history_model.appendRow(item)
self._window.le_input.setText('')
else: else:
self._window.le_input.setText('') self._window.le_input.setText('')
self._check_models() self._check_models()