Skip to content

Commit 22ca89e

Browse files
committed
Allow newline as parameter separator character and within placeholders with whitespace
1 parent bb67e34 commit 22ca89e

File tree

5 files changed

+255
-252
lines changed

5 files changed

+255
-252
lines changed

readme/README_template.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ There are two helpers to split the `parameterString` that is provided to `Comman
282282
that can then be handled separately.
283283

284284
The first is the method `Command.getParameters(...)` which you give the parameter string and the maximum amount of
285-
parameters to split into. The provided string will then be split at any arbitrary amount of consecutive non-newline
286-
whitespace characters. The last element of the returned array will have all remaining text in the parameter string. If
287-
you expect exactly three parameters without whitespaces, you should set the max parameters to four, so you can easily
288-
test the length of the returned array whether too many parameters were given to the command.
285+
parameters to split into. The provided string will then be split at any arbitrary amount of consecutive whitespace
286+
characters. The last element of the returned array will have all remaining text in the parameter string. If you expect
287+
exactly three parameters without whitespaces, you should set the max parameters to four, so you can easily test the
288+
length of the returned array whether too many parameters were given to the command.
289289

290290
The second is the [`ParameterParser`][ParameterParser JavaDoc] that you can get injected into your command. For the
291291
`ParameterParser` to work, the [usage](#command-usage) of the command has to follow a defined syntax language. This

src/main/java/net/kautler/command/api/Command.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
*/
5353
public interface Command<M> {
5454
/**
55-
* The regex pattern string for one parameter separator character. It matches one whitespaces except newline.
55+
* The regex pattern string for one parameter separator character. It matches one whitespace character.
5656
*/
57-
String PARAMETER_SEPARATOR_CHARACTER = "[\\s&&[^\\n]]";
57+
String PARAMETER_SEPARATOR_CHARACTER = "\\s";
5858

5959
/**
60-
* The pattern that is used to split parameters. It matches an arbitrary amount of whitespaces except newlines.
60+
* The pattern that is used to split parameters. It matches an arbitrary amount of whitespaces.
6161
*/
6262
Pattern PARAMETER_SEPARATOR_PATTERN = Pattern.compile(PARAMETER_SEPARATOR_CHARACTER + "++");
6363

@@ -272,7 +272,7 @@ default boolean isAsynchronous() {
272272

273273
/**
274274
* Returns an array of parameters from the given parameter string. The parameter string is split at any sequence of
275-
* non-newline whitespace characters. If you expect three parameters, you should set {@code maxParameters} to four,
275+
* whitespace characters. If you expect three parameters, you should set {@code maxParameters} to four,
276276
* so you can easily test the length of the returned array whether too many parameters were given to the command.
277277
*
278278
* <p>For a syntactically and semantically parsing of the parameter string, you can have a look at the

src/main/java/net/kautler/command/api/CommandHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected void doSetCommands(Instance<Command<? super M>> commands) {
211211
commandByAlias.keySet().stream()
212212
.map(Pattern::quote)
213213
.collect(joining("|", "(?s)^(?<alias>", ")(?=\\s|$)"
214-
+ "\\s?+" + PARAMETER_SEPARATOR_CHARACTER + "*+"
214+
+ PARAMETER_SEPARATOR_CHARACTER + "*+"
215215
+ "(?<parameterString>.*+)$")));
216216
}
217217

src/main/java/net/kautler/command/usage/UsagePatternBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public String visitPlaceholderWithWhitespace(PlaceholderWithWhitespaceContext ct
179179
String tokenText = ctx.getText();
180180
String tokenName = tokenText.substring(1, tokenText.length() - 4);
181181
return format(
182-
"%s(?<%s>.+)$",
182+
"%s(?<%s>(?s:.+))$",
183183
PRECEDED_BY_PARAMETER_SEPARATOR_CHARACTER,
184184
getGroupName(ctx, tokenName));
185185
}

0 commit comments

Comments
 (0)