From a65702be42fad22e036f4e65f5017a8a67738484 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Mon, 16 May 2022 20:31:36 -0600 Subject: [PATCH] Tapping --- .../src/python/shogoth/repl/__main__.py | 47 ++++++++++++++++--- .../python/shogoth/vm/parser/test_parser.py | 41 ++++++++++++++++ 2 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 projects/shogoth/test/python/shogoth/vm/parser/test_parser.py diff --git a/projects/shogoth/src/python/shogoth/repl/__main__.py b/projects/shogoth/src/python/shogoth/repl/__main__.py index 91be4e5..3a3da28 100644 --- a/projects/shogoth/src/python/shogoth/repl/__main__.py +++ b/projects/shogoth/src/python/shogoth/repl/__main__.py @@ -3,11 +3,46 @@ from shogoth.reader import Reader -import prompt_toolkit -import yaspin +from prompt_toolkit import ( + print_formatted_text, + PromptSession, +) +from prompt_toolkit.formatted_text import ( + FormattedText, +) +from prompt_toolkit.history import FileHistory +from prompt_toolkit.styles import Style +from yaspin import Spinner, yaspin + + +STYLE = Style.from_dict( + { + # User input (default text). + "": "", + "prompt": "ansigreen", + "time": "ansiyellow", + } +) + +SPINNER = Spinner(["|", "/", "-", "\\"], 200) + + +def main(): + reader = Reader() + session = PromptSession(history=FileHistory(".shogoth.history")) + while True: + try: + line = session.prompt([("class:prompt", ">>> ")], style=STYLE) + except (KeyboardInterrupt): + continue + except EOFError: + break + + with yaspin(SPINNER): + read = reader.read(line) + + print(read, type(read)) + if __name__ == "__main__": - reader = Reader() - while (line := input(">>> ")): - read = reader.read(line) - print(read, type(read)) + main() diff --git a/projects/shogoth/test/python/shogoth/vm/parser/test_parser.py b/projects/shogoth/test/python/shogoth/vm/parser/test_parser.py new file mode 100644 index 0000000..5f1ed2d --- /dev/null +++ b/projects/shogoth/test/python/shogoth/vm/parser/test_parser.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +from shogoth.parser import parse + +import pytest + + +@pytest.mark.parametrize('example', [ + "true", + "false", + "nil", + "foo", + '"this is a trivial string"', + r'/this is a trivial pattern/', + "[]", + "[[]]", + "[[[]]]", + "()", + "(())", + "((()))", + "{}", + + # Decimals + "10", + "01", # odd but legal + + # Octal + "0o7", + + # Binary + "0b1", + + # Hex + "0x1", + "0xF", + "0xa", + + # FIXME: Floats (ugh) +]) +def test_parses(example): + assert parse(example)