private void ReadStream(Stream stream)
        {
            using (IStyleSheetLexer lexer = new StyleSheetLexer(stream)) {
                IRuleset currentRuleset      = null;
                string   currentPropertyName = string.Empty;

                while (!lexer.EndOfStream)
                {
                    IStyleSheetLexerToken token = lexer.Peek();

                    switch (token.Type)
                    {
                    case StyleSheetLexerTokenType.DeclarationEnd:
                        rulesets.Add(currentRuleset);
                        break;

                    case StyleSheetLexerTokenType.PropertyName:
                        currentPropertyName = token.Value;
                        break;

                    case StyleSheetLexerTokenType.Value:
                    case StyleSheetLexerTokenType.Function: {
                        StyleObject[] propertyValues = ReadPropertyValues(lexer);
                        IProperty     property       = null;

                        try {
                            property = Property.Create(currentPropertyName, propertyValues);
                        }
                        catch (Exception ex) {
                            if (!options.IgnoreInvalidProperties)
                            {
                                throw ex;
                            }
                        }

                        if (property != null)
                        {
                            currentRuleset.AddProperty(property);
                        }
                    }

                        continue;

                    case StyleSheetLexerTokenType.Tag:
                    case StyleSheetLexerTokenType.Class:
                    case StyleSheetLexerTokenType.Id:
                        currentRuleset = new Ruleset(ReadSelector(lexer));
                        continue;
                    }

                    // Consume the current token.

                    lexer.Read(out _);
                }
            }
        }
Beispiel #2
0
 public static ISelector FromStream(Stream stream)
 {
     using (IStyleSheetLexer lexer = new StyleSheetLexer(stream))
         return(FromLexer(lexer));
 }