コード例 #1
0
        private void ParseAttributeEnd(Block token)
        {
            if (token.GrammarSegment == GrammarSegment.Whitespace)
            {
                return;
            }

            _selectorOperation = SelectorOperation.Data;

            if (token.GrammarSegment != GrammarSegment.SquareBracketClose)
            {
                return;
            }

            switch (_attributeOperator)
            {
            case "=":
                Insert(SimpleSelector.AttributeMatch(_attributeName, _attributeValue));
                break;

            case "~=":
                Insert(SimpleSelector.AttributeSpaceSeparated(_attributeName, _attributeValue));
                break;

            case "|=":
                Insert(SimpleSelector.AttributeDashSeparated(_attributeName, _attributeValue));
                break;

            case "^=":
                Insert(SimpleSelector.AttributeStartsWith(_attributeName, _attributeValue));
                break;

            case "$=":
                Insert(SimpleSelector.AttributeEndsWith(_attributeName, _attributeValue));
                break;

            case "*=":
                Insert(SimpleSelector.AttributeContains(_attributeName, _attributeValue));
                break;

            case "!=":
                Insert(SimpleSelector.AttributeNegatedMatch(_attributeName, _attributeValue));
                break;

            default:
                Insert(SimpleSelector.AttributeUnmatched(_attributeName));
                break;
            }
        }
コード例 #2
0
        private void Insert(BaseSelector selector)
        {
            if (_currentSelector != null)
            {
                if (!_hasCombinator)
                {
                    var compound = _currentSelector as AggregateSelectorList;

                    if (compound == null)
                    {
                        compound = new AggregateSelectorList("");
                        compound.AppendSelector(_currentSelector);
                    }

                    compound.AppendSelector(selector);
                    _currentSelector = compound;
                }
                else
                {
                    if (_complexSelector == null)
                    {
                        _complexSelector = new ComplexSelector();
                    }

                    _complexSelector.AppendSelector(_currentSelector, _combinator);
                    _combinator      = Combinator.Descendent;
                    _hasCombinator   = false;
                    _currentSelector = selector;
                }
            }
            else
            {
                if (_currentSelector == null && _complexSelector == null && _combinator == Combinator.Namespace)
                {
                    _complexSelector = new ComplexSelector();
                    _complexSelector.AppendSelector(SimpleSelector.Type(""), _combinator);
                    _currentSelector = selector;
                }
                else
                {
                    _combinator      = Combinator.Descendent;
                    _hasCombinator   = false;
                    _currentSelector = selector;
                }
            }
        }
コード例 #3
0
        private void ParseSymbol(Block token)
        {
            switch (token.GrammarSegment)
            {
            // Attribute [A]
            case GrammarSegment.SquareBraceOpen:
                _attributeName     = null;
                _attributeValue    = null;
                _attributeOperator = string.Empty;
                _selectorOperation = SelectorOperation.Attribute;
                return;

            // Pseudo :P
            case GrammarSegment.Colon:
                _selectorOperation = SelectorOperation.PseudoClass;
                return;

            // ID #I
            case GrammarSegment.Hash:
                Insert(SimpleSelector.Id(((SymbolBlock)token).Value));
                return;

            // Type E
            case GrammarSegment.Ident:
                Insert(SimpleSelector.Type(((SymbolBlock)token).Value));
                return;

            // Whitespace
            case GrammarSegment.Whitespace:
                Insert(Combinator.Descendent);
                return;

            case GrammarSegment.Delimiter:
                ParseDelimiter(token);
                return;

            case GrammarSegment.Comma:
                InsertCommaDelimited();
                return;
            }
        }
コード例 #4
0
 public SelectorList RemoveSelector(SimpleSelector selector)
 {
     Selectors.Remove(selector);
     return(this);
 }
コード例 #5
0
        private static BaseSelector GetPseudoSelector(Block token)
        {
            switch (((SymbolBlock)token).Value)
            {
            case PseudoSelectorPrefix.PseudoRoot:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoRoot));

            case PseudoSelectorPrefix.PseudoFirstOfType:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoFirstOfType));

            case PseudoSelectorPrefix.PseudoLastoftype:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoLastoftype));

            case PseudoSelectorPrefix.PseudoOnlychild:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoOnlychild));

            case PseudoSelectorPrefix.PseudoOnlyOfType:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoOnlyOfType));

            case PseudoSelectorPrefix.PseudoFirstchild:
                return(FirstChildSelector.Instance);

            case PseudoSelectorPrefix.PseudoLastchild:
                return(LastChildSelector.Instance);

            case PseudoSelectorPrefix.PseudoEmpty:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoEmpty));

            case PseudoSelectorPrefix.PseudoLink:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoLink));

            case PseudoSelectorPrefix.PseudoVisited:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoVisited));

            case PseudoSelectorPrefix.PseudoActive:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoActive));

            case PseudoSelectorPrefix.PseudoHover:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoHover));

            case PseudoSelectorPrefix.PseudoFocus:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoFocus));

            case PseudoSelectorPrefix.PseudoTarget:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoTarget));

            case PseudoSelectorPrefix.PseudoEnabled:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoEnabled));

            case PseudoSelectorPrefix.PseudoDisabled:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoDisabled));

            case PseudoSelectorPrefix.PseudoDefault:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoDefault));

            case PseudoSelectorPrefix.PseudoChecked:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoChecked));

            case PseudoSelectorPrefix.PseudoIndeterminate:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoIndeterminate));

            case PseudoSelectorPrefix.PseudoUnchecked:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoUnchecked));

            case PseudoSelectorPrefix.PseudoValid:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoValid));

            case PseudoSelectorPrefix.PseudoInvalid:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoInvalid));

            case PseudoSelectorPrefix.PseudoRequired:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoRequired));

            case PseudoSelectorPrefix.PseudoReadonly:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoReadonly));

            case PseudoSelectorPrefix.PseudoReadwrite:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoReadwrite));

            case PseudoSelectorPrefix.PseudoInrange:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoInrange));

            case PseudoSelectorPrefix.PseudoOutofrange:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoOutofrange));

            case PseudoSelectorPrefix.PseudoOptional:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoOptional));

            case PseudoSelectorPrefix.PseudoElementBefore:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoElementBefore));

            case PseudoSelectorPrefix.PseudoElementAfter:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoElementAfter));

            case PseudoSelectorPrefix.PseudoElementFirstline:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoElementFirstline));

            case PseudoSelectorPrefix.PseudoElementFirstletter:
                return(SimpleSelector.PseudoClass(PseudoSelectorPrefix.PseudoElementFirstletter));

            default:
                return(SimpleSelector.PseudoClass(token.ToString()));
            }
        }