scritcher/scritcher/main.py

29 lines
625 B
Python
Raw Normal View History

2019-06-06 20:39:47 +00:00
import sys
from pathlib import Path
2019-06-07 02:28:15 +00:00
from .executer import Interpreter, InterpreterError
2019-06-06 20:05:59 +00:00
def main():
2019-06-06 20:39:47 +00:00
try:
scri_path = Path(sys.argv[1]).resolve()
except IndexError:
print(f'usage: {sys.argv[0]} path/to/file.scri')
return
2019-06-07 02:28:15 +00:00
full_text = scri_path.read_text()
full_text = full_text.replace('\n', '')
stmts = full_text.split(';')
interp = Interpreter()
try:
for stmt in stmts:
if not stmt:
continue
interp.run(stmt)
2019-06-07 02:45:54 +00:00
print('OK')
2019-06-07 02:28:15 +00:00
except InterpreterError as err:
print(f'Interpreter error. {err.args[0]!r}')