module Sthx::Rule
Direct including types
- Sthx::Ahead
- Sthx::AttrMatch
- Sthx::Capture
- Sthx::FirstOf
- Sthx::FromRange
- Sthx::Keep
- Sthx::LongestOf
- Sthx::Refuse
- Sthx::Repeat
- Sthx::Seq
Defined in:
synthax/apply.crsynthax/rule.cr
Instance 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
. -
#apply(source : String, *, offset : Int = 0, exact : Bool = true, root : String = "root") : Apply::Result
Applies this rule to the given source string.
-
#apply!(source : String, **kwargs)
Same as
#apply?
but raisesSthx::SyntaxError
instead of returningnil
on parse error. -
#apply?(source : String, **kwargs)
Same as
#apply
but returns the resulting parse tree, ornil
on parse error.
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.
Applies this rule to the given source string. Returns an application result
(see Apply::Result
).
- source is the source string to apply this rule on;
- offset specifies the index of the character (not byte!) in the source string where to begin applying this rule.
- exact specifies whether this rule should be expected to consume the
source string entirely. If
true
, any extra characters at the end of the string are treated as an error. - root is the capture id that should be used for the root of the returned capture tree.
See also: Apply::Ok
, Apply::Err
, Tree
.
Same as #apply?
but raises Sthx::SyntaxError
instead of returning nil
on parse error.