-
Notifications
You must be signed in to change notification settings - Fork 14
/
arguments.sig
92 lines (63 loc) · 3.02 KB
/
arguments.sig
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
signature ARGUMENTS =
sig
include PARSING
where type token = string
where type Streamable.t = string list
exception Usage
exception Exit
val is : string -> unit parser (* matches and removes the string, raises SyntaxError if no match *)
val int : int parser (* raises Usage if not an int *)
val string : string parser (* same as accept *)
val eol : unit parser (* raises Usage if the stream is nonempty *)
val exec : (unit -> unit) -> unit parser (* exec f = wrap f (return ()) *)
val call : (string -> unit) -> unit parser (* call f = wrap f accept *)
val assign : 'a ref -> 'a parser -> unit parser (* assign r p = wrap (fn x => r := x) p *)
val set : bool ref -> unit parser (* set r = exec (fn () => r := true) *)
val clear : bool ref -> unit parser (* clear r = exec (fn () => r := false) *)
(* full str p
* If the first argument in the stream is str,
removes it and invokes p.
* If not, raises SyntaxError.
*)
val full : string -> unit parser -> unit parser
(* prefix str p
* If the first argument in the stream begins with str,
replaces it with the suffix after str and invokes p.
* If not, raises SyntaxError.
*)
val prefix : string -> unit parser -> unit parser
(* prefix' str p
* If the first argument in the stream begins with str, invokes p.
* If not, raises SyntaxError.
*)
val prefix' : string -> unit parser -> unit parser
(* flex str p
* If the first argument in the stream begins with str,
replaces it with the suffix after str and invokes p,
* unless that suffix is empty, in which case flex removes it
and invokes p.
* If the first argument in the stream does not begin with str,
raises SyntaxError.
*)
val flex : string -> unit parser -> unit parser
(* scan l
* Otherwise, scans the stream, trying each parser in l in order.
* If one of them succeeds, then start over with the resulting stream.
* If none of them succeeds, leave the first argument on the stream
and continue with the tail.
* If the tail is empty, do nothing.
*)
val scan : unit parser list -> unit parser
(* scanStrict l
* Scans the stream, trying each parser in l in order.
* If one of them succeeds, then start over with the resulting stream.
* If none of them succeeds, do nothing.
*)
val scanStrict : unit parser list -> unit parser
(* parse p usage args
Runs p on args.
If p returns or raises Exit, then parse returns.
If p raises Usage or SyntaxError, then parse prints usage then returns.
*)
val parse : unit parser -> string -> string list -> unit
end