Skip to content

Commit

Permalink
Fix PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsieu committed Nov 1, 2021
1 parent c177721 commit 35fb530
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ArgumentTokenizer {

/**
* Creates an ArgumentTokenizer that parses arguments specified by the given command specifications,
*
* @param specs The command specifications to parse arguments according to
*/
public ArgumentTokenizer(CommandSpecification specs) {
Expand All @@ -41,7 +42,9 @@ private CommandArgument getCommandArgumentWithPrefix(Prefix prefix) {

/**
* Tokenizes an arguments string and returns an {@code ArgumentMultimap} object that maps prefixes to their
* respective argument values. Only the given prefixes will be recognized in the arguments string.
* respective argument values. All character sequences of the form "abc/def" will be recognized as a prefix
* along with its argument. A prefix is a non-empty alphabetical sequence, while an argument to a prefix
* is the trimmed portion of text from the end of the prefix until the start of the next prefix.
*
* @param argsString Arguments string of the form: {@code preamble <prefix>value <prefix>value ...}
* @return ArgumentMultimap object that maps prefixes to their arguments
Expand Down
38 changes: 33 additions & 5 deletions src/main/java/seedu/address/logic/parser/CommandArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,70 @@ public class CommandArgument {
private final boolean isRequired;
private final boolean isMultiple;

protected CommandArgument(String name, Prefix prefix, boolean isRequired, boolean isMultiple) {
protected CommandArgument(Prefix prefix, String name, boolean isRequired, boolean isMultiple) {
assert (name != null || !prefix.equals(PREFIX_PREAMBLE));
this.name = name;
this.prefix = prefix;
this.isRequired = isRequired;
this.isMultiple = isMultiple;
}

/**
* Represents a required single argument.
*/
public static CommandArgument requiredSingle(Prefix prefix) {
return requiredSingle(prefix, null);
}

/**
* Represents a required single argument with a given argument name.
* For example: tag/TAG; tag/ is the prefix, TAG is the name.
*/
public static CommandArgument requiredSingle(Prefix prefix, String name) {
return new CommandArgument(name, prefix, true, false);
return new CommandArgument(prefix, name, true, false);
}

/**
* Represents a optional single argument.
*/
public static CommandArgument optionalSingle(Prefix prefix) {
return optionalSingle(prefix, null);
}

/**
* Represents a optional single argument with a given argument name.
* For example: tag/TAG; tag/ is the prefix, TAG is the name.
*/
public static CommandArgument optionalSingle(Prefix prefix, String name) {
return new CommandArgument(name, prefix, false, false);
return new CommandArgument(prefix, name, false, false);
}

/**
* Represents a optional multiple argument.
*/
public static CommandArgument optionalMultiple(Prefix prefix) {
return optionalMultiple(prefix, null);
}

/**
* Represents a optional multiple argument with a given argument name.
* For example: tag/TAG; tag/ is the prefix, TAG is the name.
*/
public static CommandArgument optionalMultiple(Prefix prefix, String name) {
return new CommandArgument(name, prefix, false, true);
return new CommandArgument(prefix, name, false, true);
}

/**
* Represents a prefix with unknown multiplicity. Used for extra prefixes
* that are not recognized by a given command.
*/
public static CommandArgument unknown(Prefix prefix) {
return new CommandArgument(null, prefix, false, false);
return new CommandArgument(prefix, null, false, false);
}

/*
* Represents a command argument filled with a certain value.
*/
public static FilledCommandArgument filled(Prefix prefix, String value) {
return new FilledCommandArgument(prefix, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public CommandSpecification(String word, String description, CommandArgument...

/**
* Returns the command specification with an example of a command execution added to it.
*
* @param filledCommandArguments A list of filled arguments representing the example command
* @return The same command specification, with an example of a command execution added to it
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class FilledCommandArgument extends CommandArgument {
protected FilledCommandArgument(Prefix prefix, String value) {
super(value, prefix, false, false);
super(prefix, value, false, false);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import seedu.address.logic.commands.Command;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Represents a Parser that is able to parse user input into a {@code Command} of type {@code T}.
*/
public interface Parser<T extends Command> {
/**
* Parses {@code userInput} into a command and returns it.
Expand Down

0 comments on commit 35fb530

Please sign in to comment.