private void OnDelim(Token token) { switch (token.Data[0]) { case Symbols.Comma: InsertOr(); _ready = false; break; case Symbols.GreaterThan: Insert(Combinator.Child); _ready = false; break; case Symbols.Plus: Insert(Combinator.AdjacentSibling); _ready = false; break; case Symbols.Tilde: Insert(Combinator.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() == Combinator.Descendent)) { Insert(SimpleSelector.Type(string.Empty)); } Insert(Combinator.Namespace); _ready = false; break; default: _valid = false; break; } }
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; } } }
private void OnData(Token token) { switch (token.Type) { case TokenType.SquareBracketOpen: _attrName = null; _attrValue = null; _attrOp = string.Empty; _attrNs = null; _state = State.Attribute; _ready = false; break; case TokenType.Colon: _state = State.PseudoClass; _ready = false; break; case TokenType.Hash: Insert(SimpleSelector.Id(token.Data)); _ready = true; break; case TokenType.Ident: Insert(SimpleSelector.Type(token.Data)); _ready = true; break; case TokenType.Whitespace: Insert(Combinator.Descendent); break; case TokenType.Delim: OnDelim(token); break; case TokenType.Comma: InsertOr(); _ready = false; break; default: _valid = false; break; } }
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; } }