Interface TokenDefinition

All Superinterfaces:
TokenRule
All Known Implementing Classes:
CharTokenDefinition, EscapedTokenDefinition, StringTokenDefinition, WordTokenDefinition
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface TokenDefinition extends TokenRule
Functional interface for a token definition.
A token definition defines a token and provides a method to check if a word matches the token.

For easier usage in rules this interface extends TokenRule.
This means a token definition can be used as a rule in a TokenRule.

  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull TokenDefinition
    combine(TokenDefinition @NotNull ... definitions)
    Combines multiple token definitions into a single token definition.
    The resulting token definition contains the concatenated string of all token definitions.
    If only one token definition is provided, it is returned as is.
    default @Nullable TokenRuleMatch
    match(@NotNull List<Token> tokens, int startIndex)
    Checks if the given tokens match this rule starting from the specified index.
    If the match is successful, a TokenRuleMatch is returned, otherwise null.
    boolean
    matches(@NotNull String word)
    Checks if the given word matches this token definition.
    static @NotNull TokenDefinition
    of(char token)
    Creates a new token definition for a single character.
    static @NotNull TokenDefinition
    of(@NotNull String token, boolean equalsIgnoreCase)
    Creates a new token definition for a string.
    static @NotNull TokenDefinition
    ofEscaped(char token)
    Creates a new escaped token definition for a single character.

    Methods inherited from interface net.luis.utils.io.token.rule.rules.TokenRule

    optional, repeatAtLeast, repeatAtMost, repeatBetween, repeatExactly, repeatInfinitely
  • Method Details

    • of

      @NotNull static @NotNull TokenDefinition of(char token)
      Creates a new token definition for a single character.
      Parameters:
      token - The token character
      Returns:
      The token definition
      See Also:
    • of

      @NotNull static @NotNull TokenDefinition of(@NotNull @NotNull String token, boolean equalsIgnoreCase)
      Creates a new token definition for a string.
      Parameters:
      token - The token string
      equalsIgnoreCase - If the token should be compared case insensitive
      Returns:
      The token definition
      Throws:
      NullPointerException - If the token is null
      IllegalArgumentException - If the token is empty
      See Also:
    • ofEscaped

      @NotNull static @NotNull TokenDefinition ofEscaped(char token)
      Creates a new escaped token definition for a single character.
      Parameters:
      token - The token character
      Returns:
      The token definition
      See Also:
    • combine

      @NotNull static @NotNull TokenDefinition combine(TokenDefinition @NotNull ... definitions)
      Combines multiple token definitions into a single token definition.
      The resulting token definition contains the concatenated string of all token definitions.
      If only one token definition is provided, it is returned as is.
      Parameters:
      definitions - The token definitions to combine
      Returns:
      The combined token definition
      Throws:
      NullPointerException - If the token definition array is null
      IllegalArgumentException - If the token definition array is empty or contains an unsupported token definition type
    • matches

      boolean matches(@NotNull @NotNull String word)
      Checks if the given word matches this token definition.
      Parameters:
      word - The word to check
      Returns:
      True if the word matches this token definition, false otherwise
      Throws:
      NullPointerException - If the word is null
    • match

      @Nullable default @Nullable TokenRuleMatch match(@NotNull @NotNull List<Token> tokens, int startIndex)
      Description copied from interface: TokenRule
      Checks if the given tokens match this rule starting from the specified index.
      If the match is successful, a TokenRuleMatch is returned, otherwise null.
      Specified by:
      match in interface TokenRule
      Parameters:
      tokens - The list of tokens to match against
      startIndex - The index to start matching from
      Returns:
      A token rule match if successful, otherwise null