-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.mli
More file actions
42 lines (33 loc) · 1.4 KB
/
command.mli
File metadata and controls
42 lines (33 loc) · 1.4 KB
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
type phrase = string list
(** [command] represents the verbs that the players can input. It is either
[Play], [Answer], [Score], [Quit], [Hint], or [Pass]. *)
type command =
| Play of phrase
| Answer of phrase
| Score
| Quit
| Hint
| Pass
| Skip
| Double
exception Empty
exception Malformed
(** [remove_empty lst acc] returns lst with all elements containing the empty
string removed. *)
val remove_empty : string list -> string list -> string list
(** [parse str] parses a player's input into a [command], as follows. The first
word (i.e., consecutive sequence of non-space characters) of [str] becomes
the verb. The rest of the words, if any, become the object phrase.
Examples:
- [parse " play Disney 100 "] is [Go ["Disney"; "100"]]
- [parse "quit"] is [Quit].
Requires: [str] contains only alphanumeric (A-Z, a-z, 0-9) and space
characters (only ASCII character code 32; not tabs or newlines, etc.).
Raises: [Empty] if [str] is the empty string or contains only spaces.
Raises: [Malformed] if the command is malformed. A command
is {i malformed} if the verb is neither "quit" nor "play" nor "score" nor
"who is" nor "what is", or if the verb is "quit" or "score"
and there is a non-empty object phrase,
or if the verb is "play", "who is", or "what is" and there is an
empty object phrase.*)
val parse : string -> command