|
@@ -0,0 +1,96 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2016 DMDirc Developers
|
|
3
|
+ *
|
|
4
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+ * of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+ * in the Software without restriction, including without limitation the rights
|
|
7
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+ * copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+ * furnished to do so, subject to the following conditions:
|
|
10
|
+ *
|
|
11
|
+ * The above copyright notice and this permission notice shall be included in
|
|
12
|
+ * all copies or substantial portions of the Software.
|
|
13
|
+ *
|
|
14
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+ * SOFTWARE.
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+package com.dmdirc.commandparser.parsers;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.commandparser.CommandInfo;
|
|
26
|
+import com.dmdirc.commandparser.CommandInfoPair;
|
|
27
|
+import com.dmdirc.commandparser.commands.Command;
|
|
28
|
+import com.dmdirc.interfaces.WindowModel;
|
|
29
|
+
|
|
30
|
+import javax.annotation.Nonnull;
|
|
31
|
+import javax.annotation.Nullable;
|
|
32
|
+import java.util.Map;
|
|
33
|
+
|
|
34
|
+/**
|
|
35
|
+ * A command parser takes a line of input from the user, determines if it is an attempt at executing a command (based
|
|
36
|
+ * on the character at the start of the string), and handles it appropriately.
|
|
37
|
+ */
|
|
38
|
+public interface CommandParser {
|
|
39
|
+
|
|
40
|
+ /**
|
|
41
|
+ * Registers the specified command with this parser.
|
|
42
|
+ *
|
|
43
|
+ * @param command Command to be registered
|
|
44
|
+ * @param info The information the command should be registered with
|
|
45
|
+ */
|
|
46
|
+ void registerCommand(Command command, CommandInfo info);
|
|
47
|
+
|
|
48
|
+ /**
|
|
49
|
+ * Unregisters the specified command with this parser.
|
|
50
|
+ *
|
|
51
|
+ * @param info Command information to be unregistered
|
|
52
|
+ */
|
|
53
|
+ void unregisterCommand(CommandInfo info);
|
|
54
|
+
|
|
55
|
+ /**
|
|
56
|
+ * Retrieves a map of commands known by this command parser.
|
|
57
|
+ *
|
|
58
|
+ * @return A map of commands known to this parser
|
|
59
|
+ */
|
|
60
|
+ Map<String, CommandInfoPair> getCommands();
|
|
61
|
+
|
|
62
|
+ /**
|
|
63
|
+ * Parses the specified string as a command.
|
|
64
|
+ *
|
|
65
|
+ * @param origin The container which received the command
|
|
66
|
+ * @param line The line to be parsed
|
|
67
|
+ * @param parseChannel Whether or not to try and parse the first argument as a channel name
|
|
68
|
+ */
|
|
69
|
+ void parseCommand(@Nonnull WindowModel origin, String line, boolean parseChannel);
|
|
70
|
+
|
|
71
|
+ /**
|
|
72
|
+ * Parses the specified string as a command.
|
|
73
|
+ *
|
|
74
|
+ * @param origin The container which received the command
|
|
75
|
+ * @param line The line to be parsed
|
|
76
|
+ */
|
|
77
|
+ void parseCommand(@Nonnull WindowModel origin, String line);
|
|
78
|
+
|
|
79
|
+ /**
|
|
80
|
+ * Handles the specified string as a non-command.
|
|
81
|
+ *
|
|
82
|
+ * @param origin The window in which the command was typed
|
|
83
|
+ * @param line The line to be parsed
|
|
84
|
+ */
|
|
85
|
+ void parseCommandCtrl(WindowModel origin, String line);
|
|
86
|
+
|
|
87
|
+ /**
|
|
88
|
+ * Gets the command with the given name that was previously registered with this parser.
|
|
89
|
+ *
|
|
90
|
+ * @param commandName The name of the command to retrieve.
|
|
91
|
+ * @return The command info pair, or {@code null} if the command does not exist.
|
|
92
|
+ */
|
|
93
|
+ @Nullable
|
|
94
|
+ CommandInfoPair getCommand(String commandName);
|
|
95
|
+
|
|
96
|
+}
|