public CssDecleration Parse_Decleration() { Consume_All_Whitespace(Stream); if (Stream.Next.Type != ECssTokenType.Ident) { throw new CssSyntaxErrorException(CssErrors.EXPECTING_IDENT, Stream); } CssDecleration Dec = Consume_Decleration(Stream); if (Dec is object) { throw new CssSyntaxErrorException(CssErrors.CANT_CONSUME_DECLERATION, Stream); } return(Dec); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]// Private static function called in loops, inline it static CssDecleration Consume_Decleration(DataConsumer <CssToken> Stream) { if (Stream is null) { throw new CssParserException(CssErrors.STREAM_IS_NULL); } var name = (Stream.Consume() as ValuedTokenBase).Value; CssDecleration Decleration = new CssDecleration(name); // Consume all whitespace Consume_All_Whitespace(Stream); //while (Stream.Next.Type == ECssTokenType.Whitespace) { Stream.Consume(); } if (Stream.Next.Type != ECssTokenType.Colon) { return(null); // Parser error } Stream.Consume(); // Consume the colon CssToken Token; do {// Find all of the decleration values Token = Stream.Consume(); if (Token.Type == ECssTokenType.EOF) { break; } //Decleration.Value.Add(new CssPreservedToken(Token)); Decleration.Values.Add(Token as CssComponent);// upcast to Component (Preserve the token) }while (Token.Type != ECssTokenType.EOF); CssToken A = null, B = null; // Find the last two non-whitespace tokens out of the declerations values for (int i = Decleration.Values.Count - 1; i >= 0; i--) { CssToken t = Decleration.Values[i];// (Decleration.Value[i] as CssPreservedToken).Value; if (t.Type != ECssTokenType.Whitespace) { if (B is null) { B = t; } else { A = t; break; } } } // Check if those last two values indicate this declerations 'important' flag is set if (A.Type == ECssTokenType.Delim && (A as DelimToken).Value == UnicodeCommon.CHAR_EXCLAMATION_POINT) { if (B.Type == ECssTokenType.Ident && (B as IdentToken).Value.Equals("important", StringComparison.OrdinalIgnoreCase)) { Decleration.Important = true; } } return(Decleration); }