feat(runner): add REPL welcome message and language version
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
MAX_FUNCTION_ARGS = 255
|
||||
CONSTRUCTOR_NAME = "init"
|
||||
VERSION = (0, 1, 0)
|
||||
|
||||
@@ -2,6 +2,7 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from src.consts import VERSION
|
||||
from src.interpreter.error import PebbleRuntimeError
|
||||
from src.position import Position
|
||||
from src.token import Token, TokenType
|
||||
@@ -11,6 +12,11 @@ class Pebble:
|
||||
had_error: bool = False
|
||||
had_runtime_error: bool = False
|
||||
|
||||
@staticmethod
|
||||
def version() -> str:
|
||||
major, minor, patch = VERSION
|
||||
return f"{major}.{minor}.{patch}"
|
||||
|
||||
@staticmethod
|
||||
def run_file(path: str | Path):
|
||||
source: str = ""
|
||||
|
||||
@@ -59,6 +59,9 @@ class Runner:
|
||||
interpreter: Interpreter = Interpreter()
|
||||
resolver: Resolver
|
||||
|
||||
print(f"Welcome to Pebble v{Pebble.version()}!")
|
||||
print("Press CTRL+D to quit")
|
||||
|
||||
brace_depth: int
|
||||
paren_depth: int
|
||||
buf: str = ""
|
||||
@@ -110,7 +113,11 @@ class Runner:
|
||||
if Pebble.had_error:
|
||||
Pebble.had_error = False
|
||||
continue
|
||||
|
||||
try:
|
||||
interpreter.interpret(program)
|
||||
except KeyboardInterrupt:
|
||||
print()
|
||||
|
||||
if Pebble.had_runtime_error:
|
||||
Pebble.had_runtime_error = False
|
||||
|
||||
Reference in New Issue
Block a user