Ejemplo n.º 1
0
        private static IEnumerable <TokenMatch> MatchTokens(string template,
                                                            TokenzierContext context)
        {
            var lastChars = new RollingArray(3);

            var  elementIndex = -1;
            char?isInString   = null;
            var  stringEscape = false;

            for (int i = 0; i < template.Length; i++)
            {
                var c = template[i];
                lastChars.Add(c);
                if (isInString.HasValue && context.CommentIntend == 0)
                {
                    if (c == '\\')
                    {
                        stringEscape = true;
                    }
                    else if (stringEscape && c == isInString.Value)
                    {
                        stringEscape = false;
                    }
                    else if (!stringEscape && c == isInString.Value)
                    {
                        isInString = null;
                    }
                }
                else if (lastChars.StartToken(context.PrefixToken))
                {
                    elementIndex = i - 1;
                }
                else if (elementIndex != -1 && lastChars.EndToken(context.SuffixToken))
                {
                    var token = template.Substring(elementIndex, i - elementIndex + 1);
                    yield return(new TokenMatch(elementIndex, token));

                    elementIndex = -1;
                }
                else if (elementIndex != -1 && IsStringDelimiter(c) && context.CommentIntend == 0)
                {
                    isInString = c;
                }
            }

            if (isInString.HasValue && elementIndex != -1)
            {
                var token = template.Substring(elementIndex, template.Length - elementIndex);
                yield return(new TokenMatch(elementIndex, token));
            }
        }
Ejemplo n.º 2
0
 public RollingArrayEnumerator(RollingArray <T> array)
 {
     _array      = array;
     _startIndex = _array._writerIndex;
     _index      = 0;
 }