forked from nus-cs2103-AY2223S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.java
78 lines (61 loc) · 2.39 KB
/
Parser.java
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
package meowmeow;
import meowmeow.commands.AddCommand;
import meowmeow.commands.Command;
import meowmeow.commands.DefaultCommand;
import meowmeow.commands.DeleteCommand;
import meowmeow.commands.ExitCommand;
import meowmeow.commands.FindCommand;
import meowmeow.commands.ListCommand;
import meowmeow.commands.MarkCommand;
/**
* Class Parser is a class that parses the user's input and translates it into a Command.
*/
public class Parser {
public static Command parse(String userInput) {
try {
String[] splitUI = userInput.split(" ");
switch (splitUI[0]) {
case "list":
return new ListCommand();
case "bye":
return new ExitCommand();
default:
break;
}
String[] splitUserInput = userInput.split(" ", 2);
if (splitUserInput.length <= 1) {
throw new MeowmeowException("Sowwie meowmeow doesn't understand what you said uwu");
} else {
String cmdWord = splitUserInput[0];
switch (cmdWord) {
case "mark":
int taskNum = Integer.parseInt(splitUserInput[1]);
return new MarkCommand(true, taskNum);
case "unmark":
taskNum = Integer.parseInt(splitUserInput[1]);
return new MarkCommand(false, taskNum);
case "todo":
String taskName = splitUserInput[1];
return new AddCommand('T', taskName);
case "deadline":
String nameAndLocalDateTime = splitUserInput[1];
return new AddCommand('D', nameAndLocalDateTime);
case "event":
String nameAndTime = splitUserInput[1];
return new AddCommand('E', nameAndTime);
case "delete":
int taskToDelete = Integer.parseInt(splitUserInput[1]);
return new DeleteCommand(taskToDelete);
case "find":
String taskToFind = splitUserInput[1];
return new FindCommand(taskToFind);
default:
return new DefaultCommand();
}
}
} catch (MeowmeowException e) {
System.out.println(e);
}
return new DefaultCommand();
}
}