github.com/aretext/aretext@v1.3.0/input/engine/statemachine.go (about)

     1  package engine
     2  
     3  // stateId is a unique identifier for a state.
     4  type stateId uint64
     5  
     6  // stateMachine is a discrete finite automaton (DFA) for parsing input commands.
     7  type StateMachine struct {
     8  	numStates   uint64
     9  	startState  stateId
    10  	acceptCmd   map[stateId]CmdId
    11  	transitions map[stateId][]transition
    12  }
    13  
    14  // eventRange is a range of input events (inclusive).
    15  type eventRange struct {
    16  	start, end Event
    17  }
    18  
    19  // transition represents a transition from one state to another in the DFA.
    20  type transition struct {
    21  	eventRange eventRange
    22  	nextState  stateId
    23  	captures   map[CmdId]CaptureId
    24  }