-
Notifications
You must be signed in to change notification settings - Fork 1
Instruction
The instructions used by patterns in createInstructions
.
public enum Instruction<Input: BidirectionalCollection> where Input.Element: Hashable
Unless otherwise noted, each instruction moves on to the next instruction after it has finished.
public typealias Distance = Int
Succeeds if the current element equals this element. Advances index to the next element.
case elementEquals(: Input.Element)
Succeeds if the closure returns true when passed the current element. Advances index to the next element.
case checkElement(: (Input.Element) -> Bool)
Succeeds if the closure returns true when passed the input and the input index + atIndexOffset
.
case checkIndex(: (Input, Input.Index) -> Bool, atIndexOffset: Int)
Moves the input index by offset
.
case moveIndex(offset: Distance)
Continues with the instruction at offset
relative to this instruction.
case jump(offset: Distance)
Sets the input index to the output from the closure. If the output is nil, the instruction fails.
case search(: (Input, Input.Index) -> Input.Index?)
Stores (current input index - atIndexOffset
) as the beginning of capture name
case captureStart(name: String?, atIndexOffset: Int)
Stores (current input index - atIndexOffset
) as the end of the most recently started capture.
case captureEnd(atIndexOffset: Int)
Stores a snapshot of the current state, with input index set to (current + atIndexOffset
).
case choice(offset: Distance, atIndexOffset: Int)
If there is a future failure the snapshot will be restored
and the instruction at offset
(relative to this instruction) will be called.
Signals the end of a choice. Doesn't do anything else. Used as a barrier across which instructions cannot be moved.
case choiceEnd
Discards the state saved by previous .choice
, because the instructions since then have completed
successfully and the alternative instructions at the previous .choice
are no longer needed.
case commit
Will be replaced by .call in preprocessing. Is never executed.
case openCall(name: String)
Goes to the subpattern at offset
relative to this instruction.
When the subpattern finishes we move on to the instruction after this.
case call(offset: Distance)
Returns from this subpattern to the instruction after where this was called from.
case `return`
Signals a failure.
case fail
The snapshot from the previous .choice
is restored, if there aren't any left we stop matching altogether.
A match has been successfully completed!
case match
Will not continue with further instructions.
Will be replaced in preprocessing. Is never executed.
case skip
Can this instruction be moved by moveMovablesForward
?
var isMovable: Bool
Does this instruction prohibit moveMovablesForward
from moving anything past it?
var stopsMovables: Bool
Succeeds anywhere except at the end of the input.
var any: Self
Stores the current input index as the end of the most recently started capture.
var captureEnd: Self
The offset by which this instruction will move the input index.
var movesIndexBy: Int?
Returns false only if instruction has no effect.
var doesNotDoAnything: Bool
Stores the current input index as the beginning of capture name
@inlinable public static func captureStart(name: String?) -> Self
Succeeds if the closure returns true when passed the input and the input index.
@inlinable public static func checkIndex(_ test: @escaping (Input, Input.Index) -> Bool) -> Self
Stores a snapshot of the current state.
@inlinable public static func choice(offset: Int) -> Instruction
If there is a future failure the snapshot will be restored
and the instruction at offset
(relative to this instruction) will be called.
Generated at 2020-08-23T12:56:49+0000 using swift-doc 1.0.0-beta.3.