engine

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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 AltExpr

type AltExpr struct {
	Children []Expr
}

AltExpr matches any of a set of expressions.

type CaptureExpr

type CaptureExpr struct {
	CaptureId CaptureId
	Child     Expr
}

CaptureExpr includes the matched child expression in a capture with the specified ID. Captures must NOT be nested.

type CaptureId

type CaptureId uint64

CaptureId is an identifier for a subsequence of events.

type CmdExpr

type CmdExpr struct {
	CmdId CmdId
	Expr  Expr
}

CmdExpr is an expression for a given input command.

type CmdId

type CmdId uint64

CmdId is a unique identifier for an input command.

type ConcatExpr

type ConcatExpr struct {
	Children []Expr
}

ConcatExpr matches a sequence of expressions.

type Decision

type Decision uint8

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 EventExpr

type EventExpr struct {
	Event Event
}

EventExpr matches a single input event.

type EventRangeExpr

type EventRangeExpr struct {
	StartEvent Event
	EndEvent   Event
}

EventRangeExpr matches any event in the range [start, end]. The range boundaries are inclusive.

type Expr

type Expr interface{}

Expr is a regular expression that matches input events.

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

func (r *Runtime) ProcessEvent(event Event) Result

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL