Class StringParser<C>
- All Implemented Interfaces:
ArgumentParser<C,,String> SuggestionProviderHolder<C>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic final classNested classes/interfaces inherited from interface org.incendo.cloud.parser.ArgumentParser
ArgumentParser.FutureArgumentParser<C,T> -
Constructor Summary
ConstructorsConstructorDescriptionStringParser(@NonNull StringParser.StringMode stringMode) Construct a new string parser -
Method Summary
Modifier and TypeMethodDescriptionstatic <C> @NonNull ParserDescriptor<C, String> Creates a new string parser that parses all the remaining input until it encounters a command flag.static <C> @NonNull ParserDescriptor<C, String> Creates a new string parser that parses all the remaining input.parse(@NonNull CommandContext<C> commandContext, @NonNull CommandInput commandInput) Attempts to parse theinputinto an object of typeArgumentParser.static <C> @NonNull ParserDescriptor<C, String> Creates a new string parser that parses a string surrounded by either single or double quotes, or a single string if no quotes are found.static <C> @NonNull CommandComponent.Builder<C, String> Returns aCommandComponent.BuilderusingstringComponent(StringMode)withStringParser.StringMode.SINGLEas the parser.static <C> @NonNull CommandComponent.Builder<C, String> Returns aCommandComponent.BuilderusingstringComponent(StringMode)as the parser.Returns the string mode of the parser.static <C> @NonNull ParserDescriptor<C, String> Creates a new string parser that parses a single string.static <C> @NonNull ParserDescriptor<C, String> Creates a new string parser using the givenmode.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.incendo.cloud.parser.ArgumentParser
flatMap, flatMapSuccess, mapSuccess, parseFuture, suggestionProvider
-
Constructor Details
-
StringParser
Construct a new string parser- Parameters:
stringMode- String parsing mode
-
-
Method Details
-
stringParser
@API(status=STABLE) public static <C> @NonNull ParserDescriptor<C,String> stringParser(@NonNull StringParser.StringMode mode) Creates a new string parser using the givenmode.- Type Parameters:
C- the command sender type- Parameters:
mode- the parsing mode- Returns:
- the created parser
-
stringParser
Creates a new string parser that parses a single string.- Type Parameters:
C- the command sender type- Returns:
- the created parser.
-
greedyStringParser
Creates a new string parser that parses all the remaining input.- Type Parameters:
C- the command sender type- Returns:
- the created parser.
-
greedyFlagYieldingStringParser
@API(status=STABLE) public static <C> @NonNull ParserDescriptor<C,String> greedyFlagYieldingStringParser()Creates a new string parser that parses all the remaining input until it encounters a command flag.- Type Parameters:
C- the command sender type- Returns:
- the created parser.
-
quotedStringParser
Creates a new string parser that parses a string surrounded by either single or double quotes, or a single string if no quotes are found.- Type Parameters:
C- the command sender type- Returns:
- the created parser.
-
stringComponent
@API(status=STABLE) public static <C> @NonNull CommandComponent.Builder<C,String> stringComponent(@NonNull StringParser.StringMode mode) Returns aCommandComponent.BuilderusingstringComponent(StringMode)as the parser.- Type Parameters:
C- the command sender type- Parameters:
mode- the parsing mode- Returns:
- the component builder
-
stringComponent
Returns aCommandComponent.BuilderusingstringComponent(StringMode)withStringParser.StringMode.SINGLEas the parser.- Type Parameters:
C- the command sender type- Returns:
- the component builder
-
parse
public @NonNull ArgumentParseResult<String> parse(@NonNull CommandContext<C> commandContext, @NonNull CommandInput commandInput) Description copied from interface:ArgumentParserAttempts to parse theinputinto an object of typeArgumentParser.This method may be called when a command chain is being parsed for execution (using
CommandExecutor.executeCommand(Object, String)) or when a command is being parsed to provide context for suggestions (usingSuggestionFactory.suggest(Object, String)). It is possible to useCommandContext.isSuggestions()} to see what the purpose of the parsing is. Particular care should be taken when parsing for suggestions, as the parsing method is then likely to be called once for every character written by the command sender.This method should never throw any exceptions under normal circumstances. Instead, if the parsing for some reason cannot be done successfully
ArgumentParseResult.failure(Throwable)should be returned. This then wraps any exception that should be forwarded to the command sender.The parser is assumed to be completely stateless and should not store any information about the command sender or the command context. Instead, information should be stored in the
CommandContext.- Specified by:
parsein interfaceArgumentParser<C,String> - Parameters:
commandContext- Command contextcommandInput- Command Input- Returns:
- Parsed command result
-
stringMode
Returns the string mode of the parser.- Returns:
- string mode
-