Interface TokenRule

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.

@FunctionalInterface public interface TokenRule
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 TokenRuleMatch if successful.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable TokenRuleMatch
    match(@NotNull List<Token> tokens, int startIndex)
    Checks if the given tokens match this rule starting from the specified index.
    If the match is successful, a TokenRuleMatch is returned, otherwise null.
    default @NotNull TokenRule
    Makes this token rule optional by wrapping it in an OptionalTokenRule.
    default @NotNull TokenRule
    repeatAtLeast(int min)
    Makes this token rule at least repeatable by wrapping it in a RepeatedTokenRule.
    To make the new rule match, this rule must match at least the specified number of times.
    default @NotNull TokenRule
    repeatAtMost(int max)
    Makes this token rule at most repeatable by wrapping it in a RepeatedTokenRule.
    To make the new rule match, this rule must match at most the specified number of times.
    default @NotNull TokenRule
    repeatBetween(int min, int max)
    Makes this token rule between repeatable by wrapping it in a RepeatedTokenRule.
    To make the new rule match, this rule must match at least min and at most max times.
    default @NotNull TokenRule
    repeatExactly(int repeats)
    Makes this token rule exactly repeatable by wrapping it in a RepeatedTokenRule.
    To make the new rule match, this rule must match exactly the specified number of times.
    default @NotNull TokenRule
    Makes this token rule infinitely repeatable by wrapping it in a RepeatedTokenRule.
    To make the new rule match, this rule must match at least 0 and at most Integer.MAX_VALUE times.