-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharmozeen-cli
executable file
·68 lines (52 loc) · 2.08 KB
/
armozeen-cli
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
from argparse import ArgumentParser
from sys import stdin
from armozeen.types import LanguageStage
from armozeen.utils import execute
from os import getcwd
from os.path import dirname
def argument_parser():
ap = ArgumentParser(prog='armozeen')
ap.add_argument('-s', '--set', help='Set an Armozeen parameter', action='append')
ap.add_argument('-l', '--list', help='List Armozeen parameters')
ap.add_argument('-v', '--verbose', action='store_true', help='Print verbose output')
ap.add_argument('-o', '--optimize', help='Placeholder')
ap.add_argument('-e', '--expression-tree', help='Print intermediary expression tree and exit', action='store_true')
ap.add_argument('-a', '--ast', help='Print Abstract Syntax Tree and exit', action='store_true')
ap.add_argument('-p', '--pre-grammar', help='Print Abstract Syntax Tree and exit', action='store_true')
ap.add_argument('--version', action='store_true', help='Print version information and exit')
ap.add_argument('source_file', nargs='?')
return ap
def get_input(f):
''' Either read from file passed via stdin or via `f` '''
if not f or f == '-':
return stdin.read()
with open(f, 'r') as fl:
return fl.read()
def get_config_vars():
return [
('bool', 'dump_full_arrays', 'Dumpvar will output the entire array'),
('bool', 'defer_lhs_size', 'Defer output bits metavars from usage'),
('int', 'verbose', 'Verbosity level')
]
stage = LanguageStage.Interpret
args = argument_parser().parse_args()
if args.version:
print('0.5')
exit(0)
if args.expression_tree:
stage = LanguageStage.ExpressionTree
elif args.ast:
stage = LanguageStage.AST
elif args.pre_grammar:
stage = LanguageStage.PreGrammars
conf_vars = {'cwd': getcwd(), 'path': dirname(args.source_file)}
for cfg in (args.set or []):
if '=' in cfg:
k, v = cfg.split('=', 2)
conf_vars[k] = v
else:
conf_vars[cfg] = True
result = execute(stage, get_input(args.source_file), **conf_vars)
if stage < LanguageStage.Interpret:
print(result)