Record Class BoundaryTokenRule

java.lang.Object
java.lang.Record
net.luis.utils.io.token.rule.rules.BoundaryTokenRule
Record Components:
startTokenRule - The token rule that marks the start of the sequence
betweenTokenRule - The token rule that matches the content between the start and end token rules
endTokenRule - The token rule that marks the end of the sequence
All Implemented Interfaces:
TokenRule

public record BoundaryTokenRule(@NotNull TokenRule startTokenRule, @NotNull TokenRule betweenTokenRule, @NotNull TokenRule endTokenRule) extends Record implements TokenRule
A token rule that matches a sequence of tokens with a start, between, and end token rule.
This rule is useful for matching patterns that have a specific structure, such as a start and end delimiter with optional content in between.
The start and end token rules are required, while the between token rule can match zero or infinite tokens.
The start and between token rule must not be or contain an EndTokenRule or any other token rule class that is added to INVALID_RULES.
  • Field Details

    • startTokenRule

      @NotNull private final @NotNull TokenRule startTokenRule
      The field for the startTokenRule record component.
    • betweenTokenRule

      @NotNull private final @NotNull TokenRule betweenTokenRule
      The field for the betweenTokenRule record component.
    • endTokenRule

      @NotNull private final @NotNull TokenRule endTokenRule
      The field for the endTokenRule record component.
    • INVALID_RULES

      public static final Set<Class<? extends TokenRule>> INVALID_RULES
      A set of token rules that are not allowed to be used as start or between token rule.
      This includes EndTokenRule and any other token rule class added to this set.
      API Note:
      The rules are checked recursively, so if a rule contains another rule in this set, it will also be invalid.
  • Constructor Details

    • BoundaryTokenRule

      public BoundaryTokenRule(@NotNull @NotNull TokenRule startTokenRule, @NotNull @NotNull TokenRule endTokenRule)
      Constructs a new boundary token rule with the given start, and end token rule.
      The between token rule is set to TokenRules.alwaysMatch() by default.
      Parameters:
      startTokenRule - The token rule that marks the start of the sequence
      endTokenRule - The token rule that marks the end of the sequence
      Throws:
      NullPointerException - If the start or end token rule is null
      IllegalArgumentException - If the start token rule is invalid
    • BoundaryTokenRule

      public BoundaryTokenRule(@NotNull @NotNull TokenRule startTokenRule, @NotNull @NotNull TokenRule betweenTokenRule, @NotNull @NotNull TokenRule endTokenRule)
      Constructs a new boundary token rule with the given start, between, and end token rule.
      Parameters:
      startTokenRule - The token rule that marks the start of the sequence
      betweenTokenRule - The token rule that matches the content between the start and end token rules
      endTokenRule - The token rule that marks the end of the sequence
      Throws:
      NullPointerException - If the start, between, or end token rule is null
      IllegalArgumentException - If the start or between token rule is invalid
      See Also:
  • Method Details

    • validateTokenRules

      private static void validateTokenRules(@NotNull @NotNull String type, @NotNull @NotNull Collection<TokenRule> tokenRules)
      Validates the given token rules to ensure they do not contain any invalid between token rules.
      This method is called recursively to check all nested token rules.
      Parameters:
      type - The type of the token rule to validate (e.g. "Start", "Between", "End")
      tokenRules - The collection of token rules to validate
      Throws:
      IllegalArgumentException - If any of the token rules are invalid
    • 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
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • startTokenRule

      @NotNull public @NotNull TokenRule startTokenRule()
      Returns the value of the startTokenRule record component.
      Returns:
      the value of the startTokenRule record component
    • betweenTokenRule

      @NotNull public @NotNull TokenRule betweenTokenRule()
      Returns the value of the betweenTokenRule record component.
      Returns:
      the value of the betweenTokenRule record component
    • endTokenRule

      @NotNull public @NotNull TokenRule endTokenRule()
      Returns the value of the endTokenRule record component.
      Returns:
      the value of the endTokenRule record component