private Token Reset(Token current, List<Token> result) { if (current != null) { current.Seal(); result.Add(current); } return null; }
public Token[] Split(TextReader rd) { int read; Token current = null; var result = new List<Token>(); var seperators = GetSeperators(); var symbols = GetSymbols(); bool inQuote = false; bool inComment = false; string quoteTerminator = null; string commentTerminator = null; int pos = 0; while ((read = rd.Read()) != -1) { var c = (char)read; var current_pos = pos; if(!inQuote && !inComment && CheckCommentStart(c, rd, ref pos, out commentTerminator)) { inComment = true; continue; } else if(!inQuote && inComment && CheckCommentEnd(c, rd, ref pos, commentTerminator)) { inComment = false; continue; } else if(!inQuote && inComment) { // ignore and continue pos++; continue; } if (!inQuote && !inComment && CheckQuoteStart(c, rd, ref pos, out quoteTerminator)) { inQuote = true; Reset(current, result); current = new Token(current_pos); current.Append(c); continue; } else if (inQuote && !inComment && CheckQuoteEnd(c, rd, ref pos, quoteTerminator)) { inQuote = false; current.Append(c); current = Reset(current, result); continue; } if (!inQuote && seperators.Contains(c)) { current = Reset(current, result); } else if (!inQuote && symbols.Contains(c)) { Reset(current, result); current = new Token(current_pos); current.Append(c); current = Reset(current, result); } else { if (current == null) { current = new Token(current_pos); } current.Append(c); } pos++; } return result.ToArray(); }
private Match ProcessMatch(Token working_a, Token working_b, Match currentMatch, CompareResult result) { if (currentMatch == null) { currentMatch = new Match(result); } currentMatch.TokensA.AddLast(working_a); currentMatch.TokensB.AddLast(working_b); return currentMatch; }