struct Sthx::FirstOf
- Sthx::FirstOf
- Struct
- Value
- Object
Overview
Branch. The first rule to succeed wins. This is obviously order dependent.
The order is exactly that with which this rule was initialized. So e.g. given
"x" | "xx"
and source string "xx"
the rule "x"
will always match and "xx"
will be essentially unreachable.
The faster option between FirstOf
and LongestOf
.
Included Modules
Defined in:
synthax/rule.crInstance Method Summary
-
#advance(cursor : Cursor, 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::RuleCollection
with(rule : Rule) : self
with
Constructor methods inherited from module Sthx::RuleCollection
new(rules : Array(Rule))
new
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?
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.