-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.fs
48 lines (41 loc) · 1.31 KB
/
main.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
module Main
open System
open FParsec
open Argu
open Stellite.parser
open Stellite.translator
// Command-line arguments
type CLIArguments =
| File of string
| Depth of int
with
interface IArgParserTemplate with
member s.Usage =
match s with
| File _ -> "Target file."
| Depth _ -> "Search depth."
// Build the argument parser
let argparser = ArgumentParser.Create<CLIArguments>()
let argusage = argparser.PrintUsage()
// Make a fresh number generator
let fg = freshGen ()
// Default search depth
let defaultdepth = 6
// Main function
[<EntryPoint>]
let main argv =
try let argres = argparser.Parse(argv) in
let depth = argres.GetResult (<@ Depth @>, defaultValue = defaultdepth)
let filen = argres.GetResult (<@ File @>)
match parseFile filen (parseOptScript fg) with
| Success(result,_,_) ->
// eprintfn "Parse:\n %A" result
let res = dispOptPredRelat depth filen result
for l in res do printfn "%s" l
0
| Failure(errorMsg,_,_) -> eprintfn "Parse failure %s" errorMsg; 1
with
| :? System.IO.FileNotFoundException -> eprintfn "Couldn't open the file"; 1
| :? System.ArgumentException ->
eprintf "Bad argument. Usage: %s" argusage
1