示例#1
0
        /// <summary>
        /// Lexes and parses the specified string.
        /// </summary>
        private void Parse <TSource>(TSource input, TextParserTokenStream output, Int32 index, Int32 count, TextParserOptions options = TextParserOptions.None)
            where TSource : ISegmentableStringSource
        {
            var bound = index + count;

            while (index < bound)
            {
                if (IsStartOfNewline(input, index))
                {
                    output.Add(ConsumeNewlineToken(input, options, ref index));
                    continue;
                }
                if (IsStartOfNonBreakingSpace(input, index))
                {
                    output.Add(ConsumeNonBreakingSpaceToken(input, options, ref index));
                    continue;
                }
                if (IsStartOfBreakingSpace(input, index))
                {
                    output.Add(ConsumeBreakingSpaceToken(input, options, ref index));
                    continue;
                }
                if (IsEscapedPipe(input, index, options))
                {
                    output.Add(ConsumeEscapedPipeToken(input, options, ref index));
                    continue;
                }
                if (IsStartOfCommand(input, index))
                {
                    output.Add(ConsumeCommandToken(input, options, ref index));
                    continue;
                }
                if (IsStartOfWord(input, index))
                {
                    output.Add(ConsumeWordToken(input, options, ref index));
                    continue;
                }
                index++;
            }

            output.SourceText    = input.CreateStringSegment();
            output.ParserOptions = options;
        }