public Transition(State srcState, State targetState, Condition condition, bool returnCharAfterTransition = false) { m_sourceState = srcState; m_targetState = targetState; m_returnCharAfterTransition = returnCharAfterTransition; m_condition = condition; }
private void resetState() { m_curState = m_initState; m_context.Reset(); }
private bool onChar(char ch) { bool bTransit = false; for (int i = 0; i < m_curState.Transitions.Count; i++) { Transition t = m_curState.Transitions[i]; if (t.CanTransitOnChar(this.m_context, ch)) { if (m_curState == t.TargetState) { m_context.StateToken.Append(ch); // run actions of transition if (t.TransitionAction != null) t.TransitionAction(m_context, ch); } else { // transit state m_curState = t.TargetState; // run actions of transition if (t.TransitionAction != null) t.TransitionAction(m_context, ch); if (t.ReturnCharAfterTransition) m_context.ReturnChar(); // clear token after state transition m_context.StateToken.Clear(); } bTransit = true; break; } } return bTransit; }
protected State createState(string name, bool initState = false) { State state = new State(name, m_context); if (initState) m_initState = state; return state; }
public StateTransitionHelper(State source, State target, StateContext context) { m_source = source; m_target = target; m_context = context; }
public StateTransitionHelper To(State target) { return new StateTransitionHelper(this, target, m_context); }