Class ArgumentParser<T>
java.lang.Object
net.apartium.cocoabeans.commands.parsers.ArgumentParser<T>
- Type Parameters:
T- output type
- All Implemented Interfaces:
Comparable<ArgumentParser<?>>
- Direct Known Subclasses:
BooleanParser,CompoundParser,ContextualMapBasedParser,DoubleParser,DummyParser,FloatParser,IntParser,LongParser,ParagraphParser,QuotedStringParser,RegisterArgumentParser,StringParser,StringsParser,UUIDParser,WrappedArgumentParser
Base class for all parsers
Note: That all parsers should have at least those 2 constructors
It's recommended that each implementing of ArgumentParser class should define its own DEFAULT_KEYWORD
to represent the default keyword
Note: That all parsers should have at least those 2 constructors
Parser(int priority)/Parser(int priority, String keyword)so we can use @WithParser on them- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordParse Result is the content of the parsingstatic final recordTsb completion result is the content of the tab completion -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedArgumentParser(String keyword, Class<T> clazz, int priority) Constructs a new parser -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(@NotNull ArgumentParser<?> other) Get argument typeGet type keyword, like int or stringintGet priorityabstract Optional<ArgumentParser.ParseResult<T>> parse(CommandProcessingContext processingContext) Tries to parse next argument in the contextabstract Optional<ArgumentParser.TabCompletionResult> tabCompletion(CommandProcessingContext processingContext) Retrieves available options for tab completion of this argumentabstract OptionalInttryParse(CommandProcessingContext processingContext) Tries to lazily parse next argument in the context
-
Constructor Details
-
ArgumentParser
Constructs a new parser- Parameters:
keyword- keyword of the parserclazz- output classpriority- priority
-
-
Method Details
-
parse
public abstract Optional<ArgumentParser.ParseResult<T>> parse(CommandProcessingContext processingContext) Tries to parse next argument in the context- Parameters:
processingContext- cmd processing context- Returns:
- empty if failed, otherwise result
-
tryParse
Tries to lazily parse next argument in the context- Parameters:
processingContext- cmd processing context- Returns:
- new index int if success, empty if not
-
tabCompletion
public abstract Optional<ArgumentParser.TabCompletionResult> tabCompletion(CommandProcessingContext processingContext) Retrieves available options for tab completion of this argument- Parameters:
processingContext- cmd processing context- Returns:
- tab completion result if success, otherwise empty option
-
getArgumentType
Get argument type- Returns:
- argument type
-
getPriority
public int getPriority()Get priority- Returns:
- priority
-
compareTo
- Specified by:
compareToin interfaceComparable<T>
-
getKeyword
Get type keyword, like int or string- Returns:
- type keyword
-