class

Sthx::Repeat

Inherits Sthx::Rule < Reference < Object

Repeats a rule some number of times.

Constructors

new(body : Rule, min : Int32, stop : Int32 | Nil)

Builds and returns an instance of this rule.

  • body is the rule to repeat.
  • min is the minimum number of times that body should occur.
  • stop is the maximum number of times + 1 that body should occur, i.e. the number of occurrences of body that will cause repetition to stop. If not provided the body will match until it cannot.

If min = stop this rule will match exactly min number of times. Meaning if min is also 0, this rule will be a nevermatch, e.g.: Repeat.new(body, 0, 0).

Source

Instance methods

advance(cursor : Cursor, data initial_data : TreeData, *, collect : Collect) : Advance::Result

Performs cursor motion and returns the result, one of Advance::Result: success Advance::Ok or failure Advance::Err.

data is the TreeData object built so far.

To implementors of this method: in case of failure to commit, cursor must be rolled back to its state before calling this method. In other words, advance is implemented in a "transaction" kind of way. Intermediate results and changes must never be available to the caller. This method either succeeds and mutates the cursor; or it fails and leaves the cursor intact.

Source