-
Notifications
You must be signed in to change notification settings - Fork 4
/
Program.fs
62 lines (52 loc) · 2.33 KB
/
Program.fs
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
open System
open System.Text.Json
// Please do not change the main function.
// The cases are needed for the validation and evaluation tools!
[<EntryPoint>]
let main (args) =
match args |> List.ofArray with
| ["Calculator"; input] ->
let input = JsonSerializer.Deserialize<Io.Calculator.Input> input
let output: Io.Calculator.Output = Calculator.analysis input
Console.WriteLine("{0}", JsonSerializer.Serialize output)
0
| ["Parser"; input ] ->
let input = JsonSerializer.Deserialize<Io.Parser.Input> input
let output: Io.Parser.Output = Parser.analysis input
Console.WriteLine("{0}", JsonSerializer.Serialize output)
0
| [ "Compiler"; input ] ->
let input = JsonSerializer.Deserialize<Io.Compiler.Input> input
let output: Io.Compiler.Output = Compiler.analysis input
Console.WriteLine("{0}", JsonSerializer.Serialize output)
0
| [ "Interpreter"; input ] ->
let input = JsonSerializer.Deserialize<Io.Interpreter.Input> input
let output: Io.Interpreter.Output = Interpreter.analysis input
Console.WriteLine("{0}", JsonSerializer.Serialize output)
0
| [ "Sign"; input ] ->
let input = JsonSerializer.Deserialize<Io.SignAnalysis.Input> input
let output: Io.SignAnalysis.Output = SignAnalysis.analysis input
Console.WriteLine("{0}", JsonSerializer.Serialize output)
0
| [ "Security"; input ] ->
let input = JsonSerializer.Deserialize<Io.SecurityAnalysis.Input> input
let output: Io.SecurityAnalysis.Output = SecurityAnalysis.analysis input
Console.WriteLine("{0}", JsonSerializer.Serialize output)
0
| _ ->
let commands =
[ "Calculator <INPUT>"
"Parser <INPUT>"
"Compiler <INPUT>"
"Interpreter <INPUT>"
"Sign <INPUT>"
"Security <INPUT>" ]
Console.Error.WriteLine(
"\x1B[1;31merror:\x1B[0m unrecognized input: \x1B[0;33m'{0}'\x1B[0m\n\n{1}\n\nAvailable commands:\n{2}",
String.concat " " args,
"\x1B[1mUsage: dotnet run\x1B[0m <COMMAND>",
(List.fold (fun acc cmd -> acc + sprintf " - \x1B[1m%s\x1B[0m\n" cmd) "" commands)
)
1