コード例 #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 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);
        }
コード例 #3
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);
            }
        }