- All Known Subinterfaces:
TokenDefinition
- All Known Implementing Classes:
AlwaysMatchTokenRule,AnyOfTokenRule,BoundaryTokenRule,CharTokenDefinition,EndTokenRule,EscapedTokenDefinition,OptionalTokenRule,PatternTokenRule,RepeatedTokenRule,SequenceTokenRule,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.
A functional interface representing a rule for matching tokens in a list.
It defines a method to match tokens starting from a given index and returns a
It defines a method to match tokens starting from a given index and returns a
TokenRuleMatch if successful.- See Also:
-
Method Summary
Modifier and TypeMethodDescription@Nullable TokenRuleMatchChecks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatchis returned, otherwise null.default @NotNull TokenRuleoptional()Makes this token rule optional by wrapping it in anOptionalTokenRule.default @NotNull TokenRulerepeatAtLeast(int min) Makes this token rule at least repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at least the specified number of times.default @NotNull TokenRulerepeatAtMost(int max) Makes this token rule at most repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at most the specified number of times.default @NotNull TokenRulerepeatBetween(int min, int max) Makes this token rule between repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at least min and at most max times.default @NotNull TokenRulerepeatExactly(int repeats) Makes this token rule exactly repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match exactly the specified number of times.default @NotNull TokenRuleMakes this token rule infinitely repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at least 0 and at mostInteger.MAX_VALUEtimes.
-
Method Details
-
match
Checks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatchis returned, otherwise null.- Parameters:
tokens- The list of tokens to match againststartIndex- The index to start matching from- Returns:
- A token rule match if successful, otherwise null
- Throws:
NullPointerException- If the token list is null- API Note:
- For the most rules, the start index must be less than the size of the token list.
An exception is theEndTokenRule, which can match at the end of the list.
-
optional
Makes this token rule optional by wrapping it in anOptionalTokenRule.- Returns:
- A new token rule that is optional
- See Also:
-
repeatAtLeast
Makes this token rule at least repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at least the specified number of times.- Parameters:
min- The minimum number of times this rule must match- Returns:
- A new at least repeatable token rule
- Throws:
IllegalArgumentException- If min is less than 0- See Also:
-
repeatExactly
Makes this token rule exactly repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match exactly the specified number of times.- Parameters:
repeats- The number of times this rule must match- Returns:
- A new exactly repeatable token rule
- Throws:
IllegalArgumentException- If repeats is less than 0- See Also:
-
repeatAtMost
Makes this token rule at most repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at most the specified number of times.- Parameters:
max- The maximum number of times this rule can match- Returns:
- A new at most repeatable token rule
- Throws:
IllegalArgumentException- If max is less than 0- See Also:
-
repeatInfinitely
Makes this token rule infinitely repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at least 0 and at mostInteger.MAX_VALUEtimes.- Returns:
- A new infinitely repeatable token rule
- See Also:
-
repeatBetween
Makes this token rule between repeatable by wrapping it in aRepeatedTokenRule.
To make the new rule match, this rule must match at least min and at most max times.- Parameters:
min- The minimum number of times this rule must matchmax- The maximum number of times this rule can match- Returns:
- A new between repeatable token rule
- Throws:
IllegalArgumentException- If min is less than 0 or max is less than min- See Also:
-