Example #1
0
 public void Write(CssAtGroupToken group)
 {
     _writer.Write('@');
     _writer.Write(group.Data);
     foreach (var arg in group)
     {
         Write(arg);
     }
     if (group.IsTerminated)
     {
         _writer.Write(';');
     }
 }
        /// <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);
            }
        }