Initial commit - fix problems & refactor code
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from core.parse_evaluate import parseEvaluate
|
||||
|
||||
def repl() -> None:
|
||||
stdlib_path = 'stdlib.lsp'
|
||||
if os.path.isfile(stdlib_path):
|
||||
with open(stdlib_path, 'r', encoding='utf‑8') as f:
|
||||
parseEvaluate(f.read(), load=True)
|
||||
else:
|
||||
print('>> Warning: standard library not found.')
|
||||
|
||||
if not sys.stdin.isatty():
|
||||
parseEvaluate(sys.stdin.read(), load=True)
|
||||
print('\ninput exhausted, exiting REPL...')
|
||||
return
|
||||
|
||||
prompt = '>>> '
|
||||
exit_cmds = {':q', ':quit', ':exit', 'exit', 'quit'}
|
||||
load_cmds = {':l', ':load'}
|
||||
|
||||
while True:
|
||||
try:
|
||||
line = input(prompt).strip()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print("\nexiting REPL...")
|
||||
break
|
||||
|
||||
if not line:
|
||||
continue
|
||||
|
||||
parts = line.split(None, 1)
|
||||
if not parts:
|
||||
continue
|
||||
|
||||
token = parts[0]
|
||||
|
||||
if token in exit_cmds:
|
||||
print("\nexiting REPL...")
|
||||
break
|
||||
|
||||
if token in load_cmds:
|
||||
filename = parts[1].strip() if len(parts) > 1 else ''
|
||||
if not filename:
|
||||
print(prompt + "Error: no filename provided.")
|
||||
continue
|
||||
if not os.path.isfile(filename):
|
||||
print(prompt + f'Error: no such file "{filename}"')
|
||||
continue
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
parseEvaluate(f.read(), load=True)
|
||||
print()
|
||||
continue
|
||||
|
||||
print(parseEvaluate(line))
|
||||
|
||||
if __name__ == '__main__':
|
||||
repl()
|
||||
Reference in New Issue
Block a user