CodeBox.CodeLexer.TokenList.ParseComments C# (CSharp) Метод

ParseComments() приватный Метод

private ParseComments ( string code, Position position, bool recurse ) : int
code string
position Position
recurse bool
Результат int
        private int ParseComments(string code, Position position, bool recurse)
        {
            List<Index> indices = new List<Index>();

            if ((code.Length > position.CurrentIndex + 1) && (code[position.CurrentIndex] == '/'))
            {
                if (code[position.CurrentIndex + 1] == '/')
                {
                    while ((code.Length > position.CurrentIndex) && (code[position.CurrentIndex] != '\n'))
                    {
                        indices.Add(new Index(position.LineNumber, position.CharNumber));
                        position.MoveIndex();
                    }

                    position.MoveIndex();
                }
                else if (code[position.CurrentIndex + 1] == '*')
                {
                    while (code.Length > position.CurrentIndex)
                    {
                        if (code.Length > position.CurrentIndex + 1 && code[position.CurrentIndex] == '*' && code[position.CurrentIndex + 1] == '/')
                        {
                            indices.Add(new Index(position.LineNumber, position.CharNumber));
                            indices.Add(new Index(position.LineNumber, position.CharNumber + 1));
                            position.MoveIndex();
                            position.MoveIndex();
                            break;
                        }

                        if (code.Length > position.CurrentIndex && code[position.CurrentIndex] != '\n')
                        {
                            indices.Add(new Index(position.LineNumber, position.CharNumber));
                        }

                        position.MoveIndex();
                    }
                }
            }

            EatWhitespace(code, position);

            // add token only if comments were found
            if (indices.Count > 0)
            {
                tokens.Add(new Token(TokenType.COMMENT, "", indices));
            }

            // check if next is another comment...
            if (recurse)
            {
                int oldPosition = position.CurrentIndex;
                if (ParseComments(code, position, false) != oldPosition)
                    return ParseComments(code, position, true);
            }

            return position.CurrentIndex;
        }