class Sthx::Repeat
- Sthx::Repeat
- Reference
- Object
Overview
Repeats a rule some number of times.
Included Modules
Defined in:
synthax/rule.crConstructors
-
.new(body : Rule, min : Int32, stop : Int32 | Nil)
Builds and returns an instance of this rule.
Instance Method Summary
-
#advance(cursor : Cursor, data initial_data : TreeData, *, collect : Collect) : Advance::Result
Performs cursor motion and returns the result, one of
Advance::Result
: successAdvance::Ok
or failureAdvance::Err
.
Instance methods inherited from module Sthx::Rule
advance(cursor : Cursor, data : TreeData, *, collect : Collect) : Advance::Result
advance,
apply(source : String, *, offset : Int = 0, exact : Bool = true, root : String = "root") : Apply::Result
apply,
apply!(source : String, **kwargs)
apply!,
apply?(source : String, **kwargs)
apply?
Constructor Detail
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)
.
Instance Method Detail
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.