/// <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); }
/// <summary> /// Invoked once a colon has been found in the token enumerator. /// </summary> /// <param name="token">The token.</param> /// <returns>True if no error occurred, otherwise false.</returns> Boolean OnClass(CssToken token) { state = State.Data; if (token.Type == CssTokenType.Ident) { Insert(SimpleSelector.Class(token.Data)); return(true); } return(false); }
/// <summary> /// Invoked once a colon has been found in the token enumerator. /// </summary> /// <param name="token">The token.</param> void OnClass(CssToken token) { state = State.Data; ready = true; if (token.Type == CssTokenType.Ident) { Insert(SimpleSelector.Class(token.Data)); } else { valid = false; } }
/// <summary> /// Invoked once a delimiter has been found in the token enumerator. /// </summary> /// <param name="tokens">The token source.</param> public void OnDelim(IEnumerator <CssToken> tokens) { var chr = ((CssDelimToken)tokens.Current).Data; switch (chr) { case Specification.COMMA: InsertOr(); break; case Specification.GT: Insert(CssCombinator.Child); break; case Specification.PLUS: Insert(CssCombinator.AdjacentSibling); break; case Specification.TILDE: Insert(CssCombinator.Sibling); break; case Specification.ASTERISK: Insert(SimpleSelector.All); break; case Specification.DOT: if (tokens.MoveNext() && tokens.Current.Type == CssTokenType.Ident) { var cls = (CssKeywordToken)tokens.Current; Insert(SimpleSelector.Class(cls.Data)); } else if (!ignoreErrors) { throw new DOMException(ErrorCode.SyntaxError); } else { return; } break; } }