Initial commit - fix problems & refactor code

This commit is contained in:
2025-12-22 19:10:46 +03:00
commit ff36917cb5
39 changed files with 1499 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
from core.parser.parse_expression import parseExpression
from core.evaluator.naively_evaluate import naivelyEvaluate
from core.exceptions import error
from core.environment import ENV
from traceback import print_exception
def parseEvaluate(source: str, *, load: bool = False) -> str:
results: list[str] = []
s = source
while s:
try:
expr, s = parseExpression(s)
value = naivelyEvaluate(expr, ENV, True)
results.append(repr(value))
except error as e:
# Unwrap nested causes so that the original error message is shown
cause = e
while cause.__cause__ and isinstance(cause.__cause__, error):
cause = cause.__cause__
print(cause)
break
except KeyboardInterrupt:
return "interrupted\n"
except Exception as exc:
print_exception(exc)
break
return ' '.join(results)