示例#1
0
        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", @"""");
            }
        }
示例#2
0
        public static void ExtractQuoteString(LexerCursor cursor)
        {
            bool?closed = null;

            while (!cursor.EOF)
            {
                if (cursor.Peek(null, "\""))
                {
                    if (null == closed)
                    {
                        closed = false;
                        cursor.TryMatch(KeywordQuoteContent, "\"");
                    }
                    else if (cursor.TryMatch(KeywordQuoteContent, @"([""](\~\d{1,4}(\z|(?=\s)))?)"))
                    {
                        closed = true;
                        break;
                    }
                }

                if (closed == null)
                {
                    break;
                }

                if (cursor.TryMatch(KeywordQuoteContent, @"\\[\""]"))
                {
                    continue;
                }

                // tag unexpected backslashes to be ignored
                if (cursor.TryMatch(null, @"(\\$|\\.)"))
                {
                    continue;
                }
                if (cursor.TryMatch(KeywordQuoteContent, @"[^\\\""]+"))
                {
                    continue;
                }
                // LOOP EXIT
                if (cursor.EOF)
                {
                    break;
                }
            }

            if (closed == false)
            {
                cursor.FakeMatch(KeywordQuoteContent, @"""", pop: true);
            }
        }
示例#3
0
        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);
        }
示例#4
0
 private static int GobbleUnsupported(int lastPosition, LexerCursor cursor)
 {
     if (lastPosition != cursor.Position)
     {
         lastPosition = cursor.Position;
     }
     else
     {
         cursor.TryMatch(null, ".");
     }
     return(lastPosition);
 }
示例#5
0
 private static bool ExtractSearchTerm(LexerCursor cursor)
 {
     return(cursor.TryMatch(KeywordOperand, @"(?<var>[\w\.\*\?]+)(\~0*\.\d{1,4}(\z|(?=\s)))?"));
 }
示例#6
0
 private static bool ExtractOperator(LexerCursor cursor)
 {
     return(cursor.TryMatch(KeywordOperator, @"(\bOR\b|\bAND\b)"));
 }
示例#7
0
        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);
        }
示例#8
0
 private static bool ExtractNumber(LexerCursor cursor)
 {
     return(cursor.TryMatch("NUMBER", @"\d+(\.\d+)?"));
 }
示例#9
0
 private static bool ExtractVariable(LexerCursor cursor)
 {
     return(cursor.TryMatch("ARG", @"\w([\d\w])*"));
 }