Example #1
0
        static string Render(SimpleSelector ss)
        {
            StringBuilder txt = new StringBuilder();

            if (ss.Combinator.HasValue)
            {
                switch (ss.Combinator.Value)
                {
                case JinxBot.Controls.CSS.Combinator.PrecededImmediatelyBy: txt.Append(" <span class=\"combinator\">+</span> "); break;

                case JinxBot.Controls.CSS.Combinator.ChildOf: txt.Append(" <span class=\"combinator\">&gt;</span> "); break;

                case JinxBot.Controls.CSS.Combinator.PrecededBy: txt.Append(" <span class=\"combinator\">~</span> "); break;
                }
            }
            if (ss.ElementName != null)
            {
                txt.Append(ss.ElementName);
            }
            if (ss.ID != null)
            {
                txt.AppendFormat("<span class=\"id\">#{0}</span>", ss.ID);
            }
            if (ss.Class != null)
            {
                txt.AppendFormat("<span class=\"class\">.{0}</span>", ss.Class);
            }
            if (ss.Pseudo != null)
            {
                txt.AppendFormat("<span class=\"pseudo\">:{0}</span>", ss.Pseudo);
            }
            if (ss.Attribute != null)
            {
                txt.AppendFormat("<span class=\"attribute\">{0}</span>", Render(ss.Attribute));
            }
            if (ss.Function != null)
            {
                txt.AppendFormat("<span class=\"function\">{0}</span>", Render(ss.Function));
            }
            if (ss.Child != null)
            {
                txt.AppendFormat("{1}<span class=\"simpleSelector\">{0}</span>", Render(ss.Child), ss.Child.ElementName != null ? " " : "");
            }

            return(txt.ToString());
        }
Example #2
0
        void selector(out Selector sel)
        {
            sel = new Selector();
            SimpleSelector ss = null;
            Combinator?    cb = null;

            simpleselector(out ss);
            sel.SimpleSelectors.Add(ss);
            while (StartOf(11))
            {
                if (la.kind == 28 || la.kind == 29 || la.kind == 30)
                {
                    if (la.kind == 28)
                    {
                        Get();
                        cb = Combinator.PrecededImmediatelyBy;
                    }
                    else if (la.kind == 29)
                    {
                        Get();
                        cb = Combinator.ChildOf;
                    }
                    else
                    {
                        Get();
                        cb = Combinator.PrecededBy;
                    }
                }
                simpleselector(out ss);
                if (cb.HasValue)
                {
                    ss.Combinator = cb.Value;
                }
                sel.SimpleSelectors.Add(ss);

                cb = null;
            }
        }
Example #3
0
        void simpleselector(out SimpleSelector ss)
        {
            ss = new SimpleSelector();
            string psd = null;

            JinxBot.Controls.CSS.Attribute atb = null;
            SimpleSelector parent = ss;
            string         ident  = null;

            if (StartOf(3))
            {
                identity(out ident);
                ss.ElementName = ident;
            }
            else if (la.kind == 31)
            {
                Get();
                ss.ElementName = "*";
            }
            else if (StartOf(12))
            {
                if (la.kind == 32)
                {
                    Get();
                    identity(out ident);
                    ss.ID = ident;
                }
                else if (la.kind == 33)
                {
                    Get();
                    identity(out ident);
                    ss.Class = ident;
                }
                else if (la.kind == 34)
                {
                    attrib(out atb);
                    ss.Attribute = atb;
                }
                else
                {
                    pseudo(out psd);
                    ss.Pseudo = psd;
                }
            }
            else
            {
                SynErr(54);
            }
            while (StartOf(12))
            {
                SimpleSelector child = new SimpleSelector();
                if (la.kind == 32)
                {
                    Get();
                    identity(out ident);
                    child.ID = ident;
                }
                else if (la.kind == 33)
                {
                    Get();
                    identity(out ident);
                    child.Class = ident;
                }
                else if (la.kind == 34)
                {
                    attrib(out atb);
                    child.Attribute = atb;
                }
                else
                {
                    pseudo(out psd);
                    child.Pseudo = psd;
                }
                parent.Child = child;
                parent       = child;
            }
        }
Example #4
0
        void simpleselector(out SimpleSelector ss)
        {
            ss = new SimpleSelector();
            string psd = null;
            JinxBot.Controls.CSS.Attribute atb = null;
            SimpleSelector parent = ss;
            string ident = null;

            if (StartOf(3))
            {
                identity(out ident);
                ss.ElementName = ident;
            }
            else if (la.kind == 31)
            {
                Get();
                ss.ElementName = "*";
            }
            else if (StartOf(12))
            {
                if (la.kind == 32)
                {
                    Get();
                    identity(out ident);
                    ss.ID = ident;
                }
                else if (la.kind == 33)
                {
                    Get();
                    identity(out ident);
                    ss.Class = ident;
                }
                else if (la.kind == 34)
                {
                    attrib(out atb);
                    ss.Attribute = atb;
                }
                else
                {
                    pseudo(out psd);
                    ss.Pseudo = psd;
                }
            }
            else SynErr(54);
            while (StartOf(12))
            {
                SimpleSelector child = new SimpleSelector();
                if (la.kind == 32)
                {
                    Get();
                    identity(out ident);
                    child.ID = ident;
                }
                else if (la.kind == 33)
                {
                    Get();
                    identity(out ident);
                    child.Class = ident;
                }
                else if (la.kind == 34)
                {
                    attrib(out atb);
                    child.Attribute = atb;
                }
                else
                {
                    pseudo(out psd);
                    child.Pseudo = psd;
                }
                parent.Child = child;
                parent = child;

            }
        }
Example #5
0
        static string Render(SimpleSelector ss)
        {
            StringBuilder txt = new StringBuilder();

            if (ss.Combinator.HasValue)
            {
                switch (ss.Combinator.Value)
                {
                    case JinxBot.Controls.CSS.Combinator.PrecededImmediatelyBy: txt.Append(" <span class=\"combinator\">+</span> "); break;
                    case JinxBot.Controls.CSS.Combinator.ChildOf: txt.Append(" <span class=\"combinator\">&gt;</span> "); break;
                    case JinxBot.Controls.CSS.Combinator.PrecededBy: txt.Append(" <span class=\"combinator\">~</span> "); break;
                }
            }
            if (ss.ElementName != null) { txt.Append(ss.ElementName); }
            if (ss.ID != null) { txt.AppendFormat("<span class=\"id\">#{0}</span>", ss.ID); }
            if (ss.Class != null) { txt.AppendFormat("<span class=\"class\">.{0}</span>", ss.Class); }
            if (ss.Pseudo != null) { txt.AppendFormat("<span class=\"pseudo\">:{0}</span>", ss.Pseudo); }
            if (ss.Attribute != null) { txt.AppendFormat("<span class=\"attribute\">{0}</span>", Render(ss.Attribute)); }
            if (ss.Function != null) { txt.AppendFormat("<span class=\"function\">{0}</span>", Render(ss.Function)); }
            if (ss.Child != null)
            {
                txt.AppendFormat("{1}<span class=\"simpleSelector\">{0}</span>", Render(ss.Child), ss.Child.ElementName != null ? " " : "");
            }

            return txt.ToString();
        }