Documentation ¶
Index ¶
Constants ¶
const ( DecisionWait = Decision(iota) DecisionReject DecisionAccept )
Variables ¶
This section is empty.
Functions ¶
func Serialize ¶
func Serialize(sm *StateMachine) []byte
Serialize encodes the state machine as binary.
Types ¶
type CaptureExpr ¶
CaptureExpr includes the matched child expression in a capture with the specified ID. Captures must NOT be nested.
type ConcatExpr ¶
type ConcatExpr struct {
Children []Expr
}
ConcatExpr matches a sequence of expressions.
type Event ¶
type Event int64
Event is an input event. This usually represents a keypress, but the compiled state machine doesn't assume that the events have any particular meaning.
type EventRangeExpr ¶
EventRangeExpr matches any event in the range [start, end]. The range boundaries are inclusive.
type OptionExpr ¶
type OptionExpr struct {
Child Expr
}
OptionExpr matches a child expression or an empty input sequence.
type Result ¶
type Result struct { Decision Decision CmdId CmdId // The command that was accepted. Captures map[CaptureId][]Event // Captures for the accepted command. }
Result is the result of processing a single input event.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
func NewRuntime ¶
func NewRuntime(sm *StateMachine, maxInputLen int) *Runtime
func (*Runtime) ProcessEvent ¶
ProcessEvent processes a single input event according to the runtime's program. If any command accepts the input, the runtime accepts the input and resets. If all commands reject the input, the runtime resets. Otherwise, the runtime waits for more input before making a decision.
type StarExpr ¶
type StarExpr struct {
Child Expr
}
StarExpr matches zero or more repetitions of a child expression.
type StateMachine ¶
type StateMachine struct {
// contains filtered or unexported fields
}
stateMachine is a discrete finite automaton (DFA) for parsing input commands.
func Compile ¶
func Compile(cmdExprs []CmdExpr) (*StateMachine, error)
Compile transforms a set of expressions (one for each input command) to a state machine.
func Deserialize ¶
func Deserialize(data []byte) (*StateMachine, error)
Deserialize constructs a state machine from serialized binary.