feat(repl): evaluate expression statements and print value

This commit is contained in:
2026-02-08 14:57:59 +01:00
parent e1f70e6f7f
commit d627116d35

View File

@@ -2,8 +2,9 @@ import atexit
import readline
from pathlib import Path
from src.ast.stmt import Stmt
from src.ast.stmt import Stmt, ExpressionStmt
from src.completer.completer import Completer
from src.interpreter.error import PebbleRuntimeError
from src.interpreter.interpreter import Interpreter
from src.interpreter.resolver import Resolver
from src.parser.parser import Parser
@@ -91,7 +92,15 @@ class REPL:
continue
try:
self.interpreter.interpret(program)
if len(program) == 1 and isinstance(program[0], ExpressionStmt):
stmt: ExpressionStmt = program[0] # type: ignore
try:
value = self.interpreter.evaluate(stmt.expression)
print(self.interpreter.stringify(value))
except PebbleRuntimeError as e:
Pebble.runtime_error(e)
else:
self.interpreter.interpret(program)
except KeyboardInterrupt:
print()