public override TokenResult Next() { PopHits: while (hits.Count > 0) { var hit = hits.Pop(); loops.Push(hit); if (hit.Portion.IsCompleted) { return(new TokenResult(hit.Portion.Phrase, hit.Offset, hit.Length)); } } PortionToken token = null; while ((token = reader.Read()) != null) { while (loops.Count > 0) { var hit = loops.Pop(); var nextPortion = hit.Portion.HitNext(token.Portion); if (nextPortion != null) { hit.Portion = nextPortion; hit.Length = (token.Offset + token.Length) - hit.Offset; hits.Push(hit); } } var portion = dictionary.HitPortion(token.Portion); if (portion != null) { var hit = new HitPortion(token.Offset, portion); hit.Length = token.Length; hits.Push(hit); } if (hits.Count > 0) { goto PopHits; } } return(null); }
internal void AddNext(string phrase, PhraseReader reader) { var token = reader.Read(); if (token == null) { this.Phrase = phrase; return; } var nextPortion = (PhrasePortion)this.NextPortions[token.Portion]; if (nextPortion == null) { nextPortion = new PhrasePortion(token.Portion); this.NextPortions[token.Portion] = nextPortion; } nextPortion.AddNext(phrase, reader); }
public void AddPhrase(string phrase) { if (string.IsNullOrWhiteSpace(phrase)) { return; } phrase = phrase.Trim(); var reader = new PhraseReader(phrase); var token = reader.Read(); var portion = (PhrasePortion)dictionary[token.Portion]; if (portion == null) { portion = new PhrasePortion(token.Portion); dictionary[token.Portion] = portion; } portion.AddNext(phrase, reader); }