コード例 #1
0
ファイル: Parser.cs プロジェクト: kijanawoodard/Moth
        void ruleset(out RuleSet rset)
        {
            rset = new RuleSet();
            Selector sel = null;
            Declaration dec = null;

            selector(out sel);
            rset.Selectors.Add(sel);
            while (la.kind == 4) {
                Get();
            }
            while (la.kind == 25) {
                Get();
                while (la.kind == 4) {
                    Get();
                }
                selector(out sel);
                rset.Selectors.Add(sel);
                while (la.kind == 4) {
                    Get();
                }
            }
            Expect(26);
            while (la.kind == 4) {
                Get();
            }
            if (StartOf(3)) {
                declaration(out dec);
                rset.Declarations.Add(dec);
                while (la.kind == 4) {
                    Get();
                }
                while (la.kind == 27) {
                    Get();
                    while (la.kind == 4) {
                        Get();
                    }
                    if (la.val.Equals("}")) { Get(); return; }

                    declaration(out dec);
                    rset.Declarations.Add(dec);
                    while (la.kind == 4) {
                        Get();
                    }
                }
                if (la.kind == 27) {
                    Get();
                    while (la.kind == 4) {
                        Get();
                    }
                }
            }
            Expect(28);
            while (la.kind == 4) {
                Get();
            }
        }
コード例 #2
0
 private Term GetImageTerm(RuleSet sprite)
 {
     Term term;
     if (sprite.Declarations.Any(d => d.Name == "background-image"))
     {
         term = sprite.Declarations.First(d => d.Name == "background-image").Expression.Terms.First();
     }
     else
     {
         term = sprite.Declarations.First(d => d.Name == "background").Expression.Terms.First(t => t.Type == BoneSoft.CSS.TermType.Url);
     }
     return term;
 }
コード例 #3
0
ファイル: CSSRenderer.cs プロジェクト: bpaciao/pagereleaser
        public static void RenderRuleSet(StringBuilder sb, RuleSet rs)
        {
            bool first = true;
            foreach (Selector sel in rs.Selectors)
            {
                if (first) {
                    first = false;
                } else {
                    sb.Append(",");
                }
                RenderSelector(sb, sel);
            }
            sb.Append("{");

            foreach (Declaration dec in rs.Declarations)
            {
                RenderDeclaration(sb, dec);
                sb.Append(";");
            }

            sb.Append("}");
        }
コード例 #4
0
ファイル: HTMLRenderer.cs プロジェクト: kijanawoodard/Moth
        static string Render(RuleSet rls, int nesting)
        {
            StringBuilder txt = new StringBuilder();

            string start = "";
            for (int i = 0; i < nesting; i++) {
                start += "\t";
            }

            bool first = true;
            foreach (Selector sel in rls.Selectors) {
                if (first) { first = false; txt.Append(start); } else { txt.Append(", "); }
                txt.AppendFormat("<span class=\"selector\">{0}</span>", Render(sel));
            }
            txt.Append(" {\r\n");
            txt.Append(start);

            foreach (Declaration dec in rls.Declarations) {
                txt.AppendFormat("{1}<span class=\"declaration\">{0}</span>;\r\n", Render(dec), start + "\t");
            }

            txt.Append("}");

            return txt.ToString();
        }
コード例 #5
0
        void directive(out Directive dir)
        {
            dir = new Directive();
            Declaration dec   = null;
            RuleSet     rset  = null;
            Expression  exp   = null;
            Directive   dr    = null;
            string      ident = null;
            Medium      m;

            Expect(23);
            dir.Name = "@";
            if (la.kind == 24)
            {
                Get();
                dir.Name += "-";
            }
            identity(out ident);
            dir.Name += ident;
            switch (dir.Name.ToLower())
            {
            case "@media": dir.Type = DirectiveType.Media; break;

            case "@import": dir.Type = DirectiveType.Import; break;

            case "@charset": dir.Type = DirectiveType.Charset; break;

            case "@page": dir.Type = DirectiveType.Page; break;

            case "@font-face": dir.Type = DirectiveType.FontFace; break;

            case "@namespace": dir.Type = DirectiveType.Namespace; break;

            default: dir.Type = DirectiveType.Other; break;
            }

            while (la.kind == 4)
            {
                Get();
            }
            if (StartOf(4))
            {
                if (StartOf(5))
                {
                    medium(out m);
                    dir.Mediums.Add(m);
                    while (la.kind == 4)
                    {
                        Get();
                    }
                    while (la.kind == 25)
                    {
                        Get();
                        while (la.kind == 4)
                        {
                            Get();
                        }
                        medium(out m);
                        dir.Mediums.Add(m);
                        while (la.kind == 4)
                        {
                            Get();
                        }
                    }
                }
                else
                {
                    expr(out exp);
                    dir.Expression = exp;
                    while (la.kind == 4)
                    {
                        Get();
                    }
                }
            }
            if (la.kind == 26)
            {
                Get();
                while (la.kind == 4)
                {
                    Get();
                }
                if (StartOf(6))
                {
                    while (StartOf(1))
                    {
                        if (dir.Type == DirectiveType.Page || dir.Type == DirectiveType.FontFace)
                        {
                            declaration(out dec);
                            dir.Declarations.Add(dec);
                            while (la.kind == 4)
                            {
                                Get();
                            }
                            while (la.kind == 27)
                            {
                                Get();
                                while (la.kind == 4)
                                {
                                    Get();
                                }
                                if (la.val.Equals("}"))
                                {
                                    Get(); return;
                                }
                                declaration(out dec);
                                dir.Declarations.Add(dec);
                                while (la.kind == 4)
                                {
                                    Get();
                                }
                            }
                            if (la.kind == 27)
                            {
                                Get();
                                while (la.kind == 4)
                                {
                                    Get();
                                }
                            }
                        }
                        else if (StartOf(2))
                        {
                            ruleset(out rset);
                            dir.RuleSets.Add(rset);
                            while (la.kind == 4)
                            {
                                Get();
                            }
                        }
                        else
                        {
                            directive(out dr);
                            dir.Directives.Add(dr);
                            while (la.kind == 4)
                            {
                                Get();
                            }
                        }
                    }
                }
                Expect(28);
                while (la.kind == 4)
                {
                    Get();
                }
            }
            else if (la.kind == 27)
            {
                Get();
                while (la.kind == 4)
                {
                    Get();
                }
            }
            else
            {
                SynErr(49);
            }
        }
コード例 #6
0
        void ruleset(out RuleSet rset)
        {
            rset = new RuleSet();
            Selector    sel = null;
            Declaration dec = null;

            selector(out sel);
            rset.Selectors.Add(sel);
            while (la.kind == 4)
            {
                Get();
            }
            while (la.kind == 25)
            {
                Get();
                while (la.kind == 4)
                {
                    Get();
                }
                selector(out sel);
                rset.Selectors.Add(sel);
                while (la.kind == 4)
                {
                    Get();
                }
            }
            Expect(26);
            while (la.kind == 4)
            {
                Get();
            }
            if (StartOf(3))
            {
                declaration(out dec);
                rset.Declarations.Add(dec);
                while (la.kind == 4)
                {
                    Get();
                }
                while (la.kind == 27)
                {
                    Get();
                    while (la.kind == 4)
                    {
                        Get();
                    }
                    if (la.val.Equals("}"))
                    {
                        Get(); return;
                    }

                    declaration(out dec);
                    rset.Declarations.Add(dec);
                    while (la.kind == 4)
                    {
                        Get();
                    }
                }
                if (la.kind == 27)
                {
                    Get();
                    while (la.kind == 4)
                    {
                        Get();
                    }
                }
            }
            Expect(28);
            while (la.kind == 4)
            {
                Get();
            }
        }