Class ParserContext

java.lang.Object
com.hypixel.hytale.server.core.command.system.ParserContext

public class ParserContext extends Object
A ParserContext represents the basic tokens received from the Tokenizer and gets passed through the system to a command where it eventually becomes a CommandContext
  • Constructor Details

    • ParserContext

      public ParserContext(@Nonnull List<String> tokens, @Nonnull String rawInput, @Nonnull ParseResult parseResult)
      Parameters:
      tokens - The List of String tokens from the Tokenizer
      rawInput - The original unmodified command input string
  • Method Details

    • of

      @Nonnull public static ParserContext of(@Nonnull List<String> tokens, @Nonnull String rawInput, @Nonnull ParseResult parseResult)
      Constructs a new ParserContext
      Parameters:
      tokens - The List of String tokens from the Tokenizer
      rawInput - The original unmodified command input string
    • isOptionalArgumentToken

      public static boolean isOptionalArgumentToken(@Nonnull String token)
      Whether a raw token begins an optional argument (a --name or --name=value token). This is the single definition of the optional-argument sentinel, so command parsing and console tab completion classify tokens the same way and cannot drift if the syntax changes.
    • optionalArgumentName

      @Nullable public static String optionalArgumentName(@Nonnull String token)
      Extracts the name from a --name or --name=value optional-argument token, sharing the same sentinel pattern as isOptionalArgumentToken(String) so the name and its value separator stay defined in one place. Returns null when the token is not an optional-argument token.
    • optionalArgumentInlineValue

      @Nullable public static String optionalArgumentInlineValue(@Nonnull String token)
      Extracts the inline value from a --name=value token, or null when the token carries no inline value. Uses the same pattern and quote stripping as contextualizeTokens(List, ParseResult), so completion feeds an optional the same first parameter the parser does.
    • addNewOptionalArg

      public void addNewOptionalArg(String name)
      Add a new optional argument name and create the optional arg context for it
      Parameters:
      name - the name of the optional arg that was found
    • appendOptionalParameter

      public void appendOptionalParameter(@Nonnull String value, @Nonnull ParseResult parseResult)
      Append a parameter to the last-added optional arg context
      Parameters:
      value - the parameter to add
    • getInputString

      @Nonnull public String getInputString()
    • getRawInput

      @Nonnull public String getRawInput()
    • getSubCommandIndex

      public int getSubCommandIndex()
    • isListToken

      public boolean isListToken(int index)
    • getNumPreOptSingleValueTokensBeforeListTokens

      public int getNumPreOptSingleValueTokensBeforeListTokens()
    • getNumPreOptionalTokens

      public int getNumPreOptionalTokens()
    • getPreOptionalSingleValueToken

      public String getPreOptionalSingleValueToken(int index)
    • getPreOptionalListToken

      public ParserContext.PreOptionalListContext getPreOptionalListToken(int index)
    • getFirstToken

      @Nullable public String getFirstToken()
      Returns the first token after the subcommand index, or null if none
      Returns:
      the first token after the subcommand index, or null if none
    • getOptionalArgs

      @Nonnull public it.unimi.dsi.fastutil.objects.ObjectSortedSet<Map.Entry<String, List<List<String>>>> getOptionalArgs()
    • isHelpSpecified

      public boolean isHelpSpecified()
    • isConfirmationSpecified

      public boolean isConfirmationSpecified()
      Determines whether the confirmation optional argument was specified
      Returns:
      true if the confirmation argument was specified, false otherwise
    • convertToSubCommand

      public void convertToSubCommand()