示例#1
0
 public void Write(CssPropertyToken prop)
 {
     _writer.Write(prop.Data);
     _writer.Write(':');
     foreach (var arg in prop)
     {
         Write(arg);
     }
     if (prop.IsTerminated)
     {
         _writer.Write(';');
     }
 }
示例#2
0
        /// <summary>
        /// Create properties and @-rule groups
        /// </summary>
        private static IEnumerable <CssToken> GetProperties(this IEnumerable <CssToken> reader)
        {
            using (var e = reader.GetEnumerator())
            {
                if (!e.MoveNext())
                {
                    yield break;
                }

                var prev = e.Current;
                if (e.Current.Type == CssTokenType.AtKeyword)
                {
                    prev = new CssAtGroupToken(e.Current.Data, e.Current.Position);
                }
                else
                {
                    prev = e.Current;
                }
                while (e.MoveNext())
                {
                    if (prev.Type == CssTokenType.Ident &&
                        e.Current.Data == ":")
                    {
                        prev = new CssPropertyToken(prev.Data, prev.Position);
                    }
                    else if (prev.Type == CssTokenType.Property)
                    {
                        var prop = (CssPropertyToken)prev;
                        if (prop.IsTerminated || e.Current.Data == "}" || e.Current.Data == ")")
                        {
                            yield return(prev);

                            prev = e.Current;
                        }
                        else if (e.Current.Data == ";")
                        {
                            prop.IsTerminated = true;
                        }
                        else
                        {
                            prop.AddArgumentToken(e.Current);
                        }
                    }
                    else if (prev.Type == CssTokenType.AtGroup)
                    {
                        var group = (CssAtGroupToken)prev;
                        if (group.IsTerminated || e.Current.Data == "{")
                        {
                            yield return(prev);

                            prev = e.Current;
                        }
                        else if (e.Current.Data == ";")
                        {
                            group.IsTerminated = true;
                        }
                        else
                        {
                            group.AddArgumentToken(e.Current);
                        }
                    }
                    else
                    {
                        yield return(prev);

                        if (e.Current.Type == CssTokenType.AtKeyword)
                        {
                            prev = new CssAtGroupToken(e.Current.Data, e.Current.Position);
                        }
                        else
                        {
                            prev = e.Current;
                        }
                    }
                }
                yield return(prev);
            }
        }