public IEnumerable <Token> Iter() { PhraseCharacterCounter characterCounter = new PhraseCharacterCounter(); while (cursorLocation < line.Length) { //iterate through all possible regex matches bool atLeastOneMatch = false; foreach (NamedRegex r in PossibleMatches) { Match match = r.Match(line, cursorLocation); if (match.Success) { //Convert match objects to Token classes switch (r.Type) { case MatchType.text: yield return(new TextToken(match.Groups[1].Value)); if (match.Groups[1].Value.Trim().Length != 0) { yield return(new GenericToken(match.Groups[2].Value)); } break; default: yield return(new GenericToken(match.Value)); break; } //advance the cursor to the end of the match if match cursorLocation = match.Index + match.Length; //Console.WriteLine($"Matched ({r.Type}): {match.Groups[0]} newloc:{cursorLocation}"); atLeastOneMatch = true; break; } } if (!atLeastOneMatch) { throw new Exception($"Could not parse line {line}"); } } }
public CharacterCountInserter() { lp = new LineParser(); characterCounter = new PhraseCharacterCounter(); }
public TextToken(string text) : base(text) { count = PhraseCharacterCounter.GetCharacterCount(text); }