示例#1
0
        /// <summary>
        /// Picks a simple selector from the stream of tokens.
        /// </summary>
        /// <param name="tokens">The stream of tokens to consider.</param>
        /// <returns>The created selector.</returns>
        public SimpleSelector GetSimpleSelector(IEnumerator <CssToken> tokens)
        {
            while (tokens.MoveNext())
            {
                switch (tokens.Current.Type)
                {
                //Begin of attribute [A]
                case CssTokenType.SquareBracketOpen:
                {
                    var sel = GetAttributeSelector(tokens);
                    if (sel != null)
                    {
                        return(sel);
                    }
                }
                break;

                //Begin of Pseudo :P
                case CssTokenType.Colon:
                {
                    var sel = GetPseudoSelector(tokens);
                    if (sel != null)
                    {
                        return(sel);
                    }
                }
                break;

                //Begin of ID #I
                case CssTokenType.Hash:
                    return(SimpleSelector.Id(((CssKeywordToken)tokens.Current).Data));

                //Begin of Type E
                case CssTokenType.Ident:
                    return(SimpleSelector.Type(((CssKeywordToken)tokens.Current).Data));

                //Various
                case CssTokenType.Delim:
                    if (((CssDelimToken)tokens.Current).Data == Specification.DOT && tokens.MoveNext() && tokens.Current.Type == CssTokenType.Ident)
                    {
                        return(SimpleSelector.Class(((CssKeywordToken)tokens.Current).Data));
                    }
                    break;

                //All others are being ignored
                case CssTokenType.Whitespace:
                case CssTokenType.Comma:
                default:
                    break;
                }
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// General state.
        /// </summary>
        /// <param name="token">The token to examine.</param>
        /// <returns>True if no error occurred, otherwise false.</returns>
        void OnData(CssToken token)
        {
            switch (token.Type)
            {
            //Begin of attribute [A]
            case CssTokenType.SquareBracketOpen:
                attrName  = null;
                attrValue = null;
                attrOp    = String.Empty;
                attrNs    = null;
                state     = State.Attribute;
                ready     = false;
                break;

            //Begin of Pseudo :P
            case CssTokenType.Colon:
                state = State.PseudoClass;
                ready = false;
                break;

            //Begin of ID #I
            case CssTokenType.Hash:
                Insert(SimpleSelector.Id(token.Data));
                ready = true;
                break;

            //Begin of Type E
            case CssTokenType.Ident:
                Insert(SimpleSelector.Type(token.Data));
                ready = true;
                break;

            //Whitespace could be significant
            case CssTokenType.Whitespace:
                Insert(CssCombinator.Descendent);
                break;

            //Various
            case CssTokenType.Delim:
                OnDelim(token);
                break;

            case CssTokenType.Comma:
                InsertOr();
                ready = false;
                break;

            default:
                valid = false;
                break;
            }
        }
示例#3
0
        /// <summary>
        /// Invoked once a delimiter has been found in the token enumerator.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns>True if no error occurred, otherwise false.</returns>
        void OnDelim(CssToken token)
        {
            switch (token.Data[0])
            {
            case Symbols.Comma:
                InsertOr();
                ready = false;
                break;

            case Symbols.GreaterThan:
                Insert(CssCombinator.Child);
                ready = false;
                break;

            case Symbols.Plus:
                Insert(CssCombinator.AdjacentSibling);
                ready = false;
                break;

            case Symbols.Tilde:
                Insert(CssCombinator.Sibling);
                ready = false;
                break;

            case Symbols.Asterisk:
                Insert(SimpleSelector.All);
                ready = true;
                break;

            case Symbols.Dot:
                state = State.Class;
                ready = false;
                break;

            case Symbols.Pipe:
                if (combinators.Count > 0 && combinators.Peek() == CssCombinator.Descendent)
                {
                    Insert(SimpleSelector.Type(String.Empty));
                }

                Insert(CssCombinator.Namespace);
                ready = false;
                break;

            default:
                valid = false;
                break;
            }
        }
示例#4
0
        /// <summary>
        /// Picks a simple selector from the stream of tokens.
        /// </summary>
        /// <param name="tokens">The stream of tokens to consider.</param>
        public void PickSelector(IEnumerator <CssToken> tokens)
        {
            switch (tokens.Current.Type)
            {
            //Begin of attribute [A]
            case CssTokenType.SquareBracketOpen:
                OnAttribute(tokens);
                break;

            //Begin of Pseudo :P
            case CssTokenType.Colon:
                OnColon(tokens);
                break;

            //Begin of ID #I
            case CssTokenType.Hash:
                Insert(SimpleSelector.Id(((CssKeywordToken)tokens.Current).Data));
                break;

            //Begin of Type E
            case CssTokenType.Ident:
                Insert(SimpleSelector.Type(((CssKeywordToken)tokens.Current).Data));
                break;

            //Whitespace could be significant
            case CssTokenType.Whitespace:
                Insert(CssCombinator.Descendent);
                break;

            //Various
            case CssTokenType.Delim:
                OnDelim(tokens);
                break;

            case CssTokenType.Comma:
                InsertOr();
                break;

            default:
                if (!ignoreErrors)
                {
                    throw new DOMException(ErrorCode.SyntaxError);
                }
                break;
            }
        }
        /// <summary>
        /// General state.
        /// </summary>
        /// <param name="token">The token to examine.</param>
        /// <returns>True if no error occurred, otherwise false.</returns>
        Boolean OnData(CssToken token)
        {
            switch (token.Type)
            {
            //Begin of attribute [A]
            case CssTokenType.SquareBracketOpen:
                attrName  = null;
                attrValue = null;
                attrOp    = String.Empty;
                state     = State.Attribute;
                return(true);

            //Begin of Pseudo :P
            case CssTokenType.Colon:
                state = State.PseudoClass;
                return(true);

            //Begin of ID #I
            case CssTokenType.Hash:
                Insert(SimpleSelector.Id(token.Data));
                return(true);

            //Begin of Type E
            case CssTokenType.Ident:
                Insert(SimpleSelector.Type(token.Data));
                return(true);

            //Whitespace could be significant
            case CssTokenType.Whitespace:
                Insert(CssCombinator.Descendent);
                return(true);

            //Various
            case CssTokenType.Delim:
                return(OnDelim(token));

            case CssTokenType.Comma:
                InsertOr();
                return(true);
            }

            return(false);
        }