string TransitionFunction(char c) { string ret = STATE_INIT; XmlStateTransition transition = FindTransition(c); if (transition != null) { if (transition.back == 0) { Accumulate(c); this.current_token.type = transition.state_out; } this.current_state = transition.state_out; this.read_offset -= transition.back; if (transition.acceptance) { this.tokens.Add(this.current_token); this.current_token = new XmlToken(); this.current_state = STATE_INIT; } } return(ret); }
void AddStateTransition( string state_in, string pattern, string state_out, bool acceptance = false, int back = 0 ) { XmlStateTransition transition = new XmlStateTransition( state_in, pattern, state_out, acceptance, back ); this.transition_table.Add(transition); }
XmlStateTransition FindTransition(char c) { XmlStateTransition ret = null; bool found = false; int current = 0; while (transition_table.Count > current && !found) { if (transition_table[current].state_in == this.current_state) { if (Regex.IsMatch(c.ToString(), transition_table[current].pattern)) { ret = transition_table[current]; found = true; } } current++; } return(ret); }