public static void ExtractQuoteString(LexerCursor cursor) { var closed = false; while (cursor.TryMatch("QUOTE:START", "\"")) { cursor.PassThrough("ESCAPE", @"\\."); if (cursor.TryMatch("QUOTE:END", @"""")) { closed = true; break; } cursor.PassThrough("TEXT_RUN", @"[^\\\""]+"); // LOOP EXIT if (cursor.EOF) { break; } } if (closed == false) { cursor.FakeMatch("QUOTE:END", @""""); } }
private static bool ExtractContent(LexerCursor cursor) { cursor.PassThrough(KeywordWhiteSpace, @"\s+"); ExtractQuoteString(cursor); if (cursor.TryMatch(KeywordOperator, "\\+") || cursor.TryMatch(KeywordOperator, "\\-") || cursor.TryMatch(KeywordOperator, "\\!") || cursor.TryMatch(KeywordOperator, "NOT[\\s$]")) { return(true); } if (ExtractOperator(cursor) || ExtractSearchTerm(cursor)) { return(true); } return(false); }
public static LexerCursor ParseEquation(string input) { var cursor = new LexerCursor { Input = input }; while (cursor.Peek("$", @".", false)) { // LOOP EXIT if (cursor.EOF) { break; } cursor.Ignore(@"\s+"); ExtractNumber(cursor); while (ExtractVariable(cursor)) { cursor.Ignore(@"\s+"); cursor.PassThrough("MEMBER", @"\."); // LOOP EXIT if (cursor.EOF) { break; } } cursor.Ignore(@"\s+"); ExtractQuoteString(cursor); cursor.Ignore(@"\s+"); var parenthDepthCounter = 0; while (!cursor.EOF) { cursor.TryPush("(", ref parenthDepthCounter); cursor.Ignore(@"\s+"); if (cursor.TryMatch(",")) { continue; } if (cursor.TryMatch("++")) { continue; } if (cursor.TryMatch("--")) { continue; } if (ExtractVariable(cursor)) { continue; } if (ExtractNumber(cursor)) { continue; } if (cursor.TryMatch("*")) { continue; } if (cursor.TryMatch("\\")) { continue; } if (cursor.TryMatch("%")) { continue; } if (cursor.TryMatch("+")) { continue; } if (cursor.TryMatch("-")) { continue; } if (cursor.TryMatch("===")) { continue; } if (cursor.TryMatch("<=")) { continue; } if (cursor.TryMatch(">=")) { continue; } if (cursor.TryMatch("<")) { continue; } if (cursor.TryMatch(">")) { continue; } if (cursor.TryMatch("==")) { continue; } if (cursor.TryPop(")", ref parenthDepthCounter)) { break; } cursor.PassThrough("."); } } return(cursor); }