29 lines
571 B
Python
29 lines
571 B
Python
import shlex
|
|
|
|
|
|
class InterpreterError(Exception):
|
|
pass
|
|
|
|
|
|
class Interpreter:
|
|
"""Interpreter for scritcher instructions/statements."""
|
|
def __init__(self):
|
|
pass
|
|
|
|
def _cmd_noop(self):
|
|
pass
|
|
|
|
def run(self, line: str):
|
|
"""Run a single line."""
|
|
print(f'running {line!r}')
|
|
|
|
args = shlex.split(line)
|
|
command = args[0]
|
|
|
|
try:
|
|
method = getattr(self, f'_cmd_{command}')
|
|
except AttributeError:
|
|
raise InterpreterError(f'Command {command!r} not found')
|
|
|
|
method(*args[1:])
|