-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sml
38 lines (35 loc) · 1 KB
/
run.sml
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
structure Args = struct
type t = { debug : bool, line : int, help : bool }
fun parse () : t =
let
val debug = ref false
val line = ref NONE
val help = ref false
val rec loop = fn
"-debug" :: rest => (debug := true; loop rest)
| "-help" :: rest => (help := true; loop rest)
| "-line" :: n :: rest => (line := Int.fromString n; loop rest)
| a :: _ => raise (Fail ("Unknown flag: " ^ a))
| [] =>
let
val line = case !line of
NONE => ~1
| SOME n => n
in
{ debug = !debug, line = line, help = !help }
end
in
loop (CommandLine.arguments ())
end
end
val _ =
let
val { debug, line, help } = Args.parse ()
in
if help
then print "Usage: indent < file [-help|-line N|-debug]\n"
else let in
if debug then Debug.debug := true else ()
; Indent.doit line
end
end