private static void readQuotes(StringBuilder result, PeekReader tr) { Contract.Requires(result != null); Contract.Requires(tr != null); result.Append(tr.ReadChar()); while (!tr.EOF) { if (tr.PeekMatch(ESCAPE_QUOTE)) { result.Append(tr.ReadChars(ESCAPE_QUOTE.Length)); } else if (tr.PeekMatch(QUOTE_CHAR)) { result.Append(tr.ReadChar()); return; } else { result.Append(tr.ReadChar()); } } }
private static void readSquareBrackets(StringBuilder result, PeekReader tr) { Contract.Requires(result != null); Contract.Requires(tr != null); result.Append(tr.ReadChar()); while (!tr.EOF) { if (tr.PeekMatch(BRACKET_START)) { readBrackets(result, tr); } else if (tr.PeekMatch(SQUARE_BRACKET_START)) { readSquareBrackets(result, tr); } else if (tr.PeekMatch(QUOTE_CHAR)) { readQuotes(result, tr); } else if (tr.PeekMatch(SQUARE_BRACKET_END)) { result.Append(tr.ReadChar()); return; } else { result.Append(tr.ReadChar()); } } }
private static void readAnything(StringBuilder result, PeekReader tr) { Contract.Requires(result != null); Contract.Requires(tr != null); StringBuilder text = new StringBuilder(); bool didCommand = false; while (!tr.EOF) { if (!didCommand) { text.Append(tr.ReadChar()); } didCommand = false; if (tr.PeekMatch(LOOKUP_START)) { writeText(result, text); StringBuilder commandSB = new StringBuilder(); readLookup(commandSB, tr); String command = commandSB.ToString(); if (!isSpecialDirective(command)) { result.Append("out("); result.Append(command); result.AppendLine(");"); } else { result.AppendLine(replaceSpecialDirectives(command)); } didCommand = true; } else if (tr.PeekMatch(DIRECTIVE_START)) { writeText(result, text); StringBuilder commandSB = new StringBuilder(); readDirective(commandSB, tr); String command = commandSB.ToString(); result.AppendLine(replaceSpecialDirectives(command)); didCommand = true; } } writeText(result, text); }