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 TokenRule
The field for thebetweenTokenRule
record component.private final @NotNull TokenRule
The field for theendTokenRule
record component.A set of token rules that are not allowed to be used as start or between token rule.
This includesEndTokenRule
and any other token rule class added to this set.private final @NotNull TokenRule
The field for thestartTokenRule
record 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 TokenRule
Returns the value of thebetweenTokenRule
record component.@NotNull TokenRule
Returns the value of theendTokenRule
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.@Nullable TokenRuleMatch
Checks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatch
is returned, otherwise null.@NotNull TokenRule
Returns the value of thestartTokenRule
record component.final String
toString()
Returns a string representation of this record class.private static void
validateTokenRules
(@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, wait
Methods inherited from interface net.luis.utils.io.token.rule.rules.TokenRule
optional, repeatAtLeast, repeatAtMost, repeatBetween, repeatExactly, repeatInfinitely
-
Field Details
-
startTokenRule
The field for thestartTokenRule
record component. -
betweenTokenRule
The field for thebetweenTokenRule
record component. -
endTokenRule
The field for theendTokenRule
record component. -
INVALID_RULES
A set of token rules that are not allowed to be used as start or between token rule.
This includesEndTokenRule
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 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:TokenRule
Checks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatch
is 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 thestartTokenRule
record component.- Returns:
- the value of the
startTokenRule
record component
-
betweenTokenRule
Returns the value of thebetweenTokenRule
record component.- Returns:
- the value of the
betweenTokenRule
record component
-
endTokenRule
Returns the value of theendTokenRule
record component.- Returns:
- the value of the
endTokenRule
record component
-