Exemplo n.º 1
0
        /// <summary>
        /// Finds the last token in the element's declaration.
        /// </summary>
        /// <returns>Returns the last token or null.</returns>
        private Token FindLastDeclarationToken()
        {
            CodeUnit previousToken = this.FirstDeclarationToken;

            for (CodeUnit item = previousToken; item != null; item = item.FindNextDescendentOf(this))
            {
                if (item.Is(CodeUnitType.Attribute))
                {
                    // Move to the end of the attribute.
                    item = item.FindLastDescendent();
                }
                else
                {
                    // These types indicate that we've gone past the end of the declaration.
                    if (item.Is(TokenType.OpenCurlyBracket) ||
                        item.Is(TokenType.Semicolon) ||
                        item.Is(OperatorType.Equals))
                    {
                        break;
                    }

                    // If we find an opening parenthesis, square bracket, etc., jump to its corresponding closing bracket.
                    if (item.Is(TokenType.OpenParenthesis) ||
                        item.Is(TokenType.OpenGenericBracket) ||
                        item.Is(TokenType.OpenSquareBracket))
                    {
                        item = ((OpenBracketToken)item).MatchingBracket;
                    }

                    if (item.Is(LexicalElementType.Token))
                    {
                        previousToken = item;
                    }
                }
            }

            if (previousToken != null)
            {
                while (previousToken.Parent != null && previousToken.Parent.Is(LexicalElementType.Token))
                {
                    previousToken = previousToken.Parent;
                }
            }

            return((Token)previousToken);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds the first token in the element's declaration.
        /// </summary>
        /// <returns>Returns the first token or null.</returns>
        private Token FindFirstDeclarationToken()
        {
            for (CodeUnit item = this.FindFirstDescendent(); item != null; item = item.FindNextDescendentOf(this))
            {
                if (item.Is(CodeUnitType.Attribute))
                {
                    // Move to the end of the attribute.
                    item = item.FindLastDescendent();
                }
                else if (item.Is(LexicalElementType.Token))
                {
                    return((Token)item);
                }
            }

            return(null);
        }