This commit is contained in:
Reid 'arrdem' McKenzie 2022-05-16 20:31:36 -06:00
parent 68313e8db9
commit 13355aeef4
2 changed files with 82 additions and 6 deletions

View file

@ -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()

View file

@ -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)