aboutsummaryrefslogtreecommitdiff
path: root/src/smp/__init__.py
blob: 22085ae8c94647de1d094cc28833b1d8e023138a (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
__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 = smp.macro_processor.MacroProcessor()
    res = macro_processor.process_input(data)
    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)

    with open(sys.argv[1], "r") as f:
        file_content = f.read()

    macro_processor = smp.macro_processor.MacroProcessor()
    res = macro_processor.process_input(file_content)
    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", file=sys.stderr)
    print(res)