/// <summary> /// Skip over a complete block of unknown content /// </summary> public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens) { // Save the opening token for this block OpenBlock = Children.AddCurrentAndAdvance(tokens, null); CssTokenType matchingEndType = GetMatchingTokenType(OpenBlock.TokenType); Debug.Assert(matchingEndType != CssTokenType.Unknown); // Search for the matching end of the block bool invalidBlock = false; while (!invalidBlock && tokens.CurrentToken.TokenType != matchingEndType && !tokens.CurrentToken.IsScopeBlocker()) { // Treat the contents of the block as property values so that units, functions, etc. get parsed ParseItem pi = PropertyValueHelpers.ParsePropertyValue(this, itemFactory, text, tokens); if (pi != null) { Children.Add(pi); } else { switch (tokens.CurrentToken.TokenType) { case CssTokenType.CloseCurlyBrace: case CssTokenType.CloseFunctionBrace: case CssTokenType.CloseSquareBracket: // Found a non-matching end brace/bracket, so stop parsing invalidBlock = true; break; default: Children.AddUnknownAndAdvance(itemFactory, text, tokens); break; } } } if (tokens.CurrentToken.TokenType == matchingEndType) { CloseBlock = Children.AddCurrentAndAdvance(tokens, null); } else { OpenBlock.AddParseError(ParseErrorType.CloseBraceMismatch, ParseErrorLocation.AfterItem); } return(Children.Count > 0); }
protected virtual void ParsePropertyValue(ItemFactory itemFactory, ITextProvider text, TokenStream tokens) { ParseItem item = PropertyValueHelpers.ParsePropertyValue(this, itemFactory, text, tokens); if (item != null) { Values.Add(item); Children.Add(item); } else { Children.AddUnknownAndAdvance(itemFactory, text, tokens, ParseErrorType.PropertyValueExpected); } }
protected virtual void ParseArgument(ItemFactory itemFactory, ITextProvider text, TokenStream tokens) { while (!tokens.CurrentToken.IsFunctionArgumentTerminator()) { ParseItem pi = PropertyValueHelpers.ParsePropertyValue(this, itemFactory, text, tokens); if (pi != null) { ArgumentItems.Add(pi); Children.Add(pi); } else { // An unknown item is not an error pi = Children.AddUnknownAndAdvance(itemFactory, text, tokens); ArgumentItems.Add(pi); } } }