/// <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> /// 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; } }
/// <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); }