Class TextSyntaxParser<S extends Source>

java.lang.Object
studio.mevera.imperat.TextSyntaxParser<S>

public final class TextSyntaxParser<S extends Source> extends Object
  • Method Details

    • of

      public static <S extends Source> TextSyntaxParser<S> of(Imperat<S> imperat)
    • parseSyntaxToUsage

      public CommandUsage<S> parseSyntaxToUsage(String syntax)
      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 a CommandUsage
      Returns:
      the parsed CommandUsage object
      Throws:
      IllegalArgumentException - if the syntax string is invalid
    • parseShortcutSyntax

      public Command<S> parseShortcutSyntax(Command<S> shortcutOwner, String syntax)
      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]
      • 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 types
      syntax - the syntax string to parse into a Command
      Returns:
      the parsed Command object
      Throws:
      IllegalArgumentException - if the syntax string is invalid or if parameters cannot be matched