RepeatableElement

class RepeatableElement(val element: PatternElement, val min: Int = 0, val max: Int = Int.MAX_VALUE) : PatternElement

A PatternElement that matches an element repeatedly, within a specified range of repetitions.

RepeatableElement attempts to match element as many times as possible, up to max times. The match succeeds if at least min matches are found. All matched occurrences are captured in order, and all Nodes produced by such occurrences are added to the current capture.

RepeatableElement is permitted to return a capture length of 0 (assuming min is 0). In this case, the element is considered to match successfully, but no tokens or nodes are captured. RepeatableElement immediately stops attempting to match once max is reached, even if the target Element could match additional times.

The following repeat count range constraints apply, and will result in an IllegalArgumentException if violated:

  • min must be 0 or greater

  • max must be 1 or greater

  • min must be less than or equal to max

Constructors

Link copied to clipboard
constructor(element: PatternElement, min: Int = 0, max: Int = Int.MAX_VALUE)

Properties

Link copied to clipboard

The PatternElement to repeat

Link copied to clipboard
val max: Int

The maximum number of matches allowed (default: unlimited)

Link copied to clipboard
val min: Int = 0

The minimum number of matches required (default: 0)

Functions

Link copied to clipboard
open override fun captureAt(tokenIndex: Int, capture: Node.ParserCapture): Int