Пример #1
0
        public void NotClosedByEoS()
        {
            // Literals are not closed by EOS
            string src = "\" ";

            int[] exp = { 1, 1 };

            var lit = new InLiteral();

            for (int i = 0; i != src.Length; ++i)
            {
                Assert.Equal(exp[i], lit.WithinLiteral(src[i]) ? 1 : 0);
            }

            Assert.Equal(1, lit.WithinLiteral('\0') ? 1 : 0);
        }
Пример #2
0
        public void ClosedByNewLine()
        {
            // Literals *are* closed by '\n'
            string src = "\" '\n ";

            int[] exp = { 1, 1, 1, 0, 0 };

            var lit = new InLiteral(InLiteral.EFlags.Escaped | InLiteral.EFlags.SingleLineStrings);

            for (int i = 0; i != src.Length; ++i)
            {
                Assert.Equal(exp[i], lit.WithinLiteral(src[i]) ? 1 : 0);
            }
        }
Пример #3
0
        public void MatchSameQuoteMark()
        {
            // Literals must match " to " and ' to '
            string src = "\"'\" '\"' ";

            int[] exp = { 1, 1, 1, 0, 1, 1, 1, 0 };

            var lit = new InLiteral();

            for (int i = 0; i != src.Length; ++i)
            {
                Assert.Equal(exp[i], lit.WithinLiteral(src[i]) ? 1 : 0);
            }
        }
Пример #4
0
        public void EscapedQuotesIgnored()
        {
            // Escaped quotes are ignored
            string src = " \"\\\"\" ";

            int[] exp = { 0, 1, 1, 1, 1, 0 };

            var lit = new InLiteral();

            for (int i = 0; i != src.Length; ++i)
            {
                Assert.Equal(exp[i], lit.WithinLiteral(src[i]) ? 1 : 0);
            }
        }
Пример #5
0
        public void ExcludeQuotes()
        {
            // Escape sequences are not always 1 character, but it doesn't
            // matter because we only care about escaped quotes.
            string src = " \"\\xB1\" ";

            int[] exp = { 0, 0, 1, 1, 1, 1, 0, 0 };

            // Don't include the quotes
            var lit = new InLiteral(InLiteral.EFlags.Escaped | InLiteral.EFlags.ExcludeQuotes);

            for (int i = 0; i != src.Length; ++i)
            {
                Assert.Equal(exp[i], lit.WithinLiteral(src[i]) ? 1 : 0);
            }
        }
Пример #6
0
            /// <summary>Buffer from the current position to the next keyword</summary>
            private static int BufferTemplateDeclaration(Src src)
            {
                // Stop buffering when the next keyword is found, or, if the
                // template contains a section, when the section end is found.
                var nest        = 0;
                var has_section = false;
                var lit         = new InLiteral();

                Extract.BufferWhile(src, (s, i) =>
                {
                    var ch = s[i];
                    if (lit.WithinLiteral(ch))
                    {
                        return(1);
                    }
                    nest        += "{[(<".Contains(ch) ? 1 : 0;
                    nest        -= "}])>".Contains(ch) ? 1 : 0;
                    has_section |= ch == '{';
                    if (nest > 0)
                    {
                        return(1);
                    }
                    if (nest < 0)
                    {
                        return(0);
                    }
                    if (has_section && ch == '}')
                    {
                        return(0);
                    }
                    if (!has_section && (ch == TemplateMark || ch == ReferenceMark || ch == ExpandMark))
                    {
                        return(0);
                    }
                    return(1);
                }, 1, out var len);
                if (has_section && src[len] == '}')
                {
                    ++len;
                }
                return(len);
            }