-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pony
67 lines (63 loc) · 1.79 KB
/
main.pony
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
use "cli"
use f = "files"
actor Main
new create(env: Env) =>
let cs =
try
CommandSpec.leaf("5", "PostSpite interpreter", [
OptionSpec.string("exec", "Text of program to execute"
where default' = "")
OptionSpec.string("file", "File name of program to execute"
where default' = "")], [])? .> add_help()?
else
env.err.print("error parsing command line options and args")
env.exitcode(-1)
return
end
let cmd =
match CommandParser(cs).parse(env.args, env.vars)
| let c: Command => c
| let ch: CommandHelp =>
ch.print_help(env.out)
env.exitcode(0)
return
| let se: SyntaxError =>
env.err.print(se.string())
env.exitcode(1)
return
end
let prog = match (cmd.option("exec").string(), cmd.option("file").string())
| (let p: String, "") =>
p
| ("", let file_name: String) =>
try
recover
let path = f.FilePath(env.root as AmbientAuth, file_name)?
match f.OpenFile(path)
| let file: f.File =>
String.>append(file.read(file.size()))
else
error
end
end
else
env.err.print("Error opening file '" + file_name + "'")
env.exitcode(1)
return
end
else
env.err.print("you must specify either a filename or a program")
env.exitcode(-1)
return
end
let sm = PostSpiteMachine
match PostSpiteLangParser.process(prog)
| let start_inst: PostSpiteInstruction box =>
let sp = PostSpiteProgram(start_inst)
sp.run(sm, env.out, env.err)
| let e: PostSpiteError =>
env.err.print("parse error")
env.err.print(e.message())
env.exitcode(-1)
return
end