コード例 #1
0
        public static LexerCursor ParseQuery(string input)
        {
            var cursor = new LexerCursor {
                Input    = input,
                MaxStack = 256
            };

            var lastPosition = -1;

            while (cursor.Peek("$", @".", false))
            {
                // LOOP EXIT
                if (cursor.EOF)
                {
                    break;
                }

                if (ExtractContent(cursor))
                {
                    continue;
                }
                // ignore closing parentheses if not in the context of group
                cursor.Ignore(@"\)");
                var closuresRequired = 0;
                while (!cursor.EOF)
                {
                    lastPosition = GobbleUnsupported(lastPosition, cursor);
                    if (!cursor.TryPush(KeywordParenthesesOpen, @"\(", ref closuresRequired))
                    {
                        break;
                    }


                    if (ExtractContent(cursor))
                    {
                        continue;
                    }

                    var exitPop = cursor.TryPop(KeywordParenthesesClose, @"\)", ref closuresRequired);

                    if (exitPop)
                    {
                        break;
                    }
                }

                while (closuresRequired > 0)
                {
                    closuresRequired--;
                    cursor.FakeMatch(KeywordParenthesesClose, @")", pop: true);
                }
            }

            return(cursor);
        }
コード例 #2
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);
        }