Class AlwaysMatchTokenRule

java.lang.Object
net.luis.utils.io.token.rule.rules.AlwaysMatchTokenRule
All Implemented Interfaces:
TokenRule

@Singleton public final class AlwaysMatchTokenRule extends Object implements TokenRule
A token rule that always matches a single token if the start index is valid.
This rule is useful for testing or as a default case in a chain of token rules.
This class is implemented as a singleton and can be accessed via TokenRules.alwaysMatch() or INSTANCE.
  • Field Details

    • INSTANCE

      public static final AlwaysMatchTokenRule INSTANCE
      The singleton instance of this class.
  • Constructor Details

    • AlwaysMatchTokenRule

      private AlwaysMatchTokenRule()
      Private constructor to prevent instantiation.
  • Method Details

    • match

      @Nullable public @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