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 sequencebetweenTokenRule- The token rule that matches the content between the start and end token rulesendTokenRule- 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
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final @NotNull TokenRuleThe field for thebetweenTokenRulerecord component.private final @NotNull TokenRuleThe field for theendTokenRulerecord component.A set of token rules that are not allowed to be used as start or between token rule.
This includesEndTokenRuleand any other token rule class added to this set.private final @NotNull TokenRuleThe field for thestartTokenRulerecord component. -
Constructor Summary
ConstructorsConstructorDescriptionBoundaryTokenRule(@NotNull TokenRule startTokenRule, @NotNull TokenRule endTokenRule) Constructs a new boundary token rule with the given start, and end token rule.
The between token rule is set toTokenRules.alwaysMatch()by default.BoundaryTokenRule(@NotNull TokenRule startTokenRule, @NotNull TokenRule betweenTokenRule, @NotNull TokenRule endTokenRule) Constructs a new boundary token rule with the given start, between, and end token rule. -
Method Summary
Modifier and TypeMethodDescription@NotNull TokenRuleReturns the value of thebetweenTokenRulerecord component.@NotNull TokenRuleReturns the value of theendTokenRulerecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@Nullable TokenRuleMatchChecks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatchis returned, otherwise null.@NotNull TokenRuleReturns the value of thestartTokenRulerecord component.final StringtoString()Returns a string representation of this record class.private static voidvalidateTokenRules(@NotNull String type, @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.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.luis.utils.io.token.rule.rules.TokenRule
optional, repeatAtLeast, repeatAtMost, repeatBetween, repeatExactly, repeatInfinitely
-
Field Details
-
startTokenRule
The field for thestartTokenRulerecord component. -
betweenTokenRule
The field for thebetweenTokenRulerecord component. -
endTokenRule
The field for theendTokenRulerecord component. -
INVALID_RULES
A set of token rules that are not allowed to be used as start or between token rule.
This includesEndTokenRuleand 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 toTokenRules.alwaysMatch()by default.- Parameters:
startTokenRule- The token rule that marks the start of the sequenceendTokenRule- The token rule that marks the end of the sequence- Throws:
NullPointerException- If the start or end token rule is nullIllegalArgumentException- 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 sequencebetweenTokenRule- The token rule that matches the content between the start and end token rulesendTokenRule- The token rule that marks the end of the sequence- Throws:
NullPointerException- If the start, between, or end token rule is nullIllegalArgumentException- 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:TokenRuleChecks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatchis returned, otherwise null. -
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
startTokenRule
Returns the value of thestartTokenRulerecord component.- Returns:
- the value of the
startTokenRulerecord component
-
betweenTokenRule
Returns the value of thebetweenTokenRulerecord component.- Returns:
- the value of the
betweenTokenRulerecord component
-
endTokenRule
Returns the value of theendTokenRulerecord component.- Returns:
- the value of the
endTokenRulerecord component
-