Package studio.mevera.imperat
Class TextSyntaxParser<S extends Source>
java.lang.Object
studio.mevera.imperat.TextSyntaxParser<S>
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends Source>
TextSyntaxParser<S>parseShortcutSyntax(Command<S> shortcutOwner, String syntax) Parses a shortcut command syntax string into a Command object.parseSyntaxToUsage(String syntax) Parses a command syntax string into a CommandUsage object.
-
Method Details
-
of
-
parseSyntaxToUsage
Parses a command syntax string into a CommandUsage object. The syntax string should follow the format: - It must start with the command name, optionally prefixed by the command prefix (e.g., "/"). - Followed by parameters which can be: - Required arguments::type - Optional arguments: [argName]:type - True-flags (flags with input): [-flag ]:type - Switches (boolean flags): [--switchFlag] - Parameters are separated by spaces. NOTE: For custom parameter types, ensure they are registered in the Imperat configuration, The only supported generic-based parameter types arethe one which are set/registered: - Primitive Array typesONLY (e.g., String[], Integer[]) are also supported. - Parameterized types like List
, Map<String, Integer> etc are supported. - Custom generic types like CustomType are supported if specifically set. - Parameters:
syntax- the syntax string to parse into aCommandUsage- Returns:
- the parsed
CommandUsageobject - Throws:
IllegalArgumentException- if the syntax string is invalid
-
parseShortcutSyntax
Parses a shortcut command syntax string into a Command object. The syntax string should follow the format:- It must start with the command name, optionally prefixed by the command prefix (e.g.,
"/"). - Followed by parameters which can be:
- Required arguments:
<argName> - Optional arguments:
[argName] - True-flags (flags with input):
[-flag <value>] - Switches (boolean flags):
[--switchFlag]
- Required arguments:
- Parameters are separated by spaces.
NOTE: This method does not support specifying parameter types in the syntax. It infers parameter types from the provided shortcutOwner command's usages. The only supported parameter types are those already defined in the shortcutOwner command.
- Parameters:
shortcutOwner- the command whose parameters will be used to infer typessyntax- the syntax string to parse into aCommand- Returns:
- the parsed
Commandobject - Throws:
IllegalArgumentException- if the syntax string is invalid or if parameters cannot be matched
- It must start with the command name, optionally prefixed by the command prefix (e.g.,
-