aboutsummaryrefslogtreecommitdiff
path: root/src/smp/__init__.py
blob: 898e683de447f12a5725d30abd8c02cef11bb1c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
__version__ = "0.0.1"
import smp.macro_processor
import smp.builtins

__all__ = [
    "smp.macro_processor",
    "smp.builtins",
]


def repl():
    print("=Skaldpress Macro Processor (REPL)")
    # print(" type \"quit\" to exit");
    print("NOT IMPLEMENTED")
    # Intend to use code.InteractiveConsole or code.InteractiveInterpreter
    # as well as the readline library


def read_stdin():
    import sys

    data = sys.stdin.read()
    macro_processor_state = smp.macro_processor.MacroProcessorState()
    macro_processor = macro_processor_state.macro_processor()
    macro_processor._enter_file_frame("[stdin]", 0, None)
    res = macro_processor.process_input(data, file="[stdin]")
    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", file=sys.stderr)
    print(res)


def main():
    import sys

    if not sys.stdin.isatty():
        read_stdin()
        sys.exit(0)

    if len(sys.argv) > 1 and sys.argv[1] == "-":
        read_stdin()
        sys.exit(0)

    if len(sys.argv) == 1:
        repl()
        sys.exit(0)

    macro_processor_state = smp.macro_processor.MacroProcessorState()
    macro_processor = macro_processor_state.macro_processor()
    res = smp.builtins._smp_builtin_read(macro_processor, sys.argv[1])
    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", file=sys.stderr)
    print(res)

    for warning in macro_processor.warnings:
        print(f"\u001b[33m{warning}\u001b[0m", file=sys.stderr)