public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens) { // foo : bar rgb(1,2,3) "baz" url(quux) / moo goo ! important ; // First item is property name. Allow -webkit and *foo - the latter is used for 'commenting out' PropertyName = ParseName(itemFactory, text, tokens); if (tokens.CurrentToken.TokenType == CssTokenType.Colon || tokens.CurrentToken.TokenType == CssTokenType.DoubleColon) { Colon = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.Punctuation); if (Colon.TokenType != CssTokenType.Colon) { Colon.AddParseError(ParseErrorType.UnexpectedToken, ParseErrorLocation.WholeItem); } } // Parse values while (KeepParsingValues(tokens)) { switch (tokens.CurrentToken.TokenType) { case CssTokenType.Bang: ParseBang(itemFactory, text, tokens); break; default: ParseDefaultChild(itemFactory, text, tokens); break; } } ParseAfterValues(itemFactory, text, tokens); // Add appropriate errors if (PropertyName == null) { AddParseError(ParseErrorType.PropertyNameMissing, ParseErrorLocation.BeforeItem); } else if (Colon != null) { int semiColonIndex = (Semicolon != null) ? Children.IndexOf(Semicolon) : Children.Count; if (Children.IndexOf(Colon) + 1 == semiColonIndex) { Colon.AddParseError(ParseErrorType.PropertyValueMissing, ParseErrorLocation.AfterItem); } } else { AddColonMissingError(); } return(Children.Count > 0); }
public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens) { if (tokens.CurrentToken.TokenType == CssTokenType.Identifier && TextRange.CompareDecoded(tokens.CurrentToken.Start, tokens.CurrentToken.Length, text, "and", true)) { MediaCombineOperator = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.MediaCombineOperator); } if (tokens.CurrentToken.TokenType == CssTokenType.OpenFunctionBrace) { OpenFunctionBrace = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.FunctionBrace); ParseFeatureName(itemFactory, text, tokens); if (tokens.CurrentToken.TokenType == CssTokenType.Colon) { Colon = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.Punctuation); } while (tokens.CurrentToken.TokenType != CssTokenType.CloseFunctionBrace && tokens.CurrentToken.TokenType != CssTokenType.OpenCurlyBrace && !tokens.CurrentToken.IsScopeBlocker()) { ParseNextValue(itemFactory, text, tokens); } if (tokens.CurrentToken.TokenType == CssTokenType.CloseFunctionBrace) { CloseFunctionBrace = Children.AddCurrentAndAdvance(tokens, CssClassifierContextType.FunctionBrace); } else { OpenFunctionBrace.AddParseError(ParseErrorType.CloseFunctionBraceMissing, ParseErrorLocation.AfterItem); } if ((Colon != null && Children[Children.Count - 1] == Colon) || (Colon != null && CloseFunctionBrace != null && Children.IndexOf(Colon) + 1 == Children.IndexOf(CloseFunctionBrace))) { // There was nothing between the colon and close brace Colon.AddParseError(ParseErrorType.PropertyValueMissing, ParseErrorLocation.AfterItem); } } if (MediaCombineOperator != null && OpenFunctionBrace == null) { MediaCombineOperator.AddParseError(ParseErrorType.MediaExpressionExpected, ParseErrorLocation.AfterItem); } return(Children.Count > 0); }