Exemple #1
0
        internal static BaseSelector ParseSelector(string selector)
        {
            var tokenizer = new Lexer(new StylesheetReader(selector));
            var tokens    = tokenizer.Tokens;
            var selctor   = new SelectorFactory();

            foreach (var token in tokens)
            {
                selctor.Apply(token);
            }

            var result = selctor.GetSelector();

            return(result);
        }
Exemple #2
0
        private void ParsePseudoClassFunction(Block token)
        {
            if (token.GrammarSegment == GrammarSegment.Whitespace)
            {
                return;
            }

            switch (_attributeName)
            {
            case PseudoSelectorPrefix.PseudoFunctionNthchild:
            case PseudoSelectorPrefix.PseudoFunctionNthlastchild:
            case PseudoSelectorPrefix.PseudoFunctionNthOfType:
            case PseudoSelectorPrefix.PseudoFunctionNthLastOfType:
            {
                switch (token.GrammarSegment)
                {
                case GrammarSegment.Ident:
                case GrammarSegment.Number:
                case GrammarSegment.Dimension:
                    _attributeValue += token.ToString();
                    return;

                case GrammarSegment.Delimiter:
                    var chr = ((DelimiterBlock)token).Value;

                    if (chr == Specification.PlusSign || chr == Specification.MinusSign)
                    {
                        _attributeValue += chr;
                        return;
                    }

                    break;
                }

                break;
            }

            case PseudoSelectorPrefix.PseudoFunctionNot:
            {
                if (_nestedSelectorFactory == null)
                {
                    _nestedSelectorFactory = new SelectorFactory();
                }

                if (token.GrammarSegment != GrammarSegment.ParenClose || _nestedSelectorFactory._selectorOperation != SelectorOperation.Data)
                {
                    _nestedSelectorFactory.Apply(token);
                    return;
                }

                break;
            }

            case PseudoSelectorPrefix.PseudoFunctionDir:
            {
                if (token.GrammarSegment == GrammarSegment.Ident)
                {
                    _attributeValue = ((SymbolBlock)token).Value;
                }

                _selectorOperation = SelectorOperation.PseudoClassFunctionEnd;
                return;
            }

            case PseudoSelectorPrefix.PseudoFunctionLang:
            {
                if (token.GrammarSegment == GrammarSegment.Ident)
                {
                    _attributeValue = ((SymbolBlock)token).Value;
                }

                _selectorOperation = SelectorOperation.PseudoClassFunctionEnd;
                return;
            }

            case PseudoSelectorPrefix.PseudoFunctionContains:
            {
                switch (token.GrammarSegment)
                {
                case GrammarSegment.String:
                    _attributeValue = ((StringBlock)token).Value;
                    break;

                case GrammarSegment.Ident:
                    _attributeValue = ((SymbolBlock)token).Value;
                    break;
                }

                _selectorOperation = SelectorOperation.PseudoClassFunctionEnd;
                return;
            }
            }

            PrasePseudoClassFunctionEnd(token);
        }