-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_exec.py
50 lines (40 loc) · 1.23 KB
/
search_exec.py
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
#!/usr/bin/env python3.8
import argparse
import os
import sys
from io import StringIO
from search_parser.search_tokenize import generate_tokens
from search_parser.tokenizer import Tokenizer
from search_parser.generator3 import check, generate
from search_parser.visualizer import Visualizer
from search_parser.search import SearchParser
argparser = argparse.ArgumentParser()
argparser.add_argument("program", nargs="*", help="Program to parse")
argparser.add_argument("-v", "--visualize", action="store_true", help="Use visualizer")
def main():
args = argparser.parse_args()
file = StringIO(' '.join(args.program))
tokengen = generate_tokens(file.readline)
vis = None
if args.visualize:
vis = Visualizer()
try:
tok = Tokenizer(tokengen, vis)
p = SearchParser(tok)
program = p.start()
if vis:
vis.done()
finally:
if vis:
vis.close()
if not program:
if tok.tokens:
last = tok.tokens[-1]
print(f"Line {last.start[0]}:")
print(last.line)
print(" "*last.start[1] + "^")
sys.exit("SyntaxError")
print(repr(program))
print(str(program))
if __name__ == '__main__':
main()