예제 #1
0
        static string Render(Model.Term t)
        {
            StringBuilder txt = new StringBuilder();

            // leave off seperator

            if (t.Type == Model.TermType.Function)
            {
                txt.AppendFormat("<span class=\"value_function function\">{0}</span>", Render(t.Function));
            }
            else if (t.Type == Model.TermType.Url)
            {
                txt.AppendFormat("<span class=\"value_url\">url('{0}')</span>", t.Value);
            }
            else if (t.Type == Model.TermType.Unicode)
            {
                txt.AppendFormat("<span class=\"value_unicode\">U\\{0}</span>", t.Value.ToUpper());
            }
            else if (t.Type == Model.TermType.Hex)
            {
                txt.AppendFormat("<span class=\"value_hex{1}\">{0}</span>", t.Value.ToUpper(), t.IsColor ? " value_color" : "");
            }
            else
            {
                if (t.Type == Model.TermType.Number)
                {
                    txt.Append("<span class=\"value_number\">");
                }
                else
                {
                    txt.AppendFormat("<span class=\"value_string{0}\">", t.IsColor ? " value_color" : "");
                }
                if (t.Sign.HasValue)
                {
                    txt.AppendFormat("<span class=\"values_sign\">{0}</span>", t.Sign.Value);
                }
                txt.Append(t.Value);
                if (t.Unit.HasValue)
                {
                    txt.Append("<span class=\"values_unit\">");
                    if (t.Unit.Value == breinstormin.tools.web.css.Model.Unit.Percent)
                    {
                        txt.Append("%");
                    }
                    else
                    {
                        txt.Append(Model.UnitOutput.ToString(t.Unit.Value));
                    }
                    txt.Append("</span>");
                }
                txt.Append("</span>");
            }

            return(txt.ToString());
        }
예제 #2
0
        void expr(out Model.Expression exp)
        {
            exp = new Model.Expression();
            char?sep = null;

            Model.Term trm = null;

            term(out trm);
            exp.Terms.Add(trm);
            while (la.kind == 4)
            {
                Get();
            }
            while (StartOf(11))
            {
                if (la.kind == 25 || la.kind == 46)
                {
                    if (la.kind == 46)
                    {
                        Get();
                        sep = '/';
                    }
                    else
                    {
                        Get();
                        sep = ',';
                    }
                    while (la.kind == 4)
                    {
                        Get();
                    }
                }
                term(out trm);
                if (sep.HasValue)
                {
                    trm.Seperator = sep.Value;
                }
                exp.Terms.Add(trm);
                sep = null;

                while (la.kind == 4)
                {
                    Get();
                }
            }
        }
예제 #3
0
        void term(out Model.Term trm)
        {
            trm = new Model.Term();
            string val = "";
            Model.Expression exp = null;
            string ident = null;

            if (la.kind == 7 || la.kind == 8) {
                QuotedString(out val);
                trm.Value = val; trm.Type = Model.TermType.String;
            } else if (la.kind == 9) {
                URI(out val);
                trm.Value = val; trm.Type = Model.TermType.Url;
            } else if (la.kind == 47) {
                Get();
                identity(out ident);
                trm.Value = "U\\" + ident; trm.Type = Model.TermType.Unicode;
            } else if (la.kind == 33) {
                HexValue(out val);
                trm.Value = val; trm.Type = Model.TermType.Hex;
            } else if (StartOf(15)) {
                bool minus = false;
                if (la.kind == 24) {
                    Get();
                    minus = true;
                }
                if (StartOf(16)) {
                    identity(out ident);
                    trm.Value = ident; trm.Type = Model.TermType.String;
                    if (minus) { trm.Value = "-" + trm.Value; }
                    while (la.kind == 4) {
                        Get();
                    }
                    if (StartOf(17)) {
                        while (la.kind == 34 || la.kind == 36 || la.kind == 43) {
                            if (la.kind == 43) {
                                Get();
                                trm.Value += t.val;
                                if (StartOf(18)) {
                                    if (la.kind == 43) {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                    if (la.kind == 24) {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                    identity(out ident);
                                    trm.Value += ident;
                                } else if (la.kind == 33) {
                                    HexValue(out val);
                                    trm.Value += val;
                                } else if (StartOf(19)) {
                                    while (la.kind == 3) {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                    if (la.kind == 34) {
                                        Get();
                                        trm.Value += ".";
                                        while (la.kind == 3) {
                                            Get();
                                            trm.Value += t.val;
                                        }
                                    }
                                } else SynErr(57);
                            } else if (la.kind == 34) {
                                Get();
                                trm.Value += t.val;
                                if (la.kind == 24) {
                                    Get();
                                    trm.Value += t.val;
                                }
                                identity(out ident);
                                trm.Value += ident;
                            } else {
                                Get();
                                trm.Value += t.val;
                                while (la.kind == 4) {
                                    Get();
                                }
                                if (la.kind == 24) {
                                    Get();
                                    trm.Value += t.val;
                                }
                                if (StartOf(16)) {
                                    identity(out ident);
                                    trm.Value += ident;
                                } else if (StartOf(19)) {
                                    while (la.kind == 3) {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                } else SynErr(58);
                            }
                        }
                    }
                    if (la.kind == 10) {
                        Get();
                        while (la.kind == 4) {
                            Get();
                        }
                        expr(out exp);
                        Model.Function func = new Model.Function();
                        func.Name = trm.Value;
                        func.Expression = exp;
                        trm.Value = null;
                        trm.Function = func;
                        trm.Type = Model.TermType.Function;

                        while (la.kind == 4) {
                            Get();
                        }
                        Expect(11);
                    }
                } else if (StartOf(15)) {
                    if (la.kind == 29) {
                        Get();
                        trm.Sign = '+';
                    }
                    if (minus) { trm.Sign = '-'; }
                    while (la.kind == 3) {
                        Get();
                        val += t.val;
                    }
                    if (la.kind == 34) {
                        Get();
                        val += t.val;
                        while (la.kind == 3) {
                            Get();
                            val += t.val;
                        }
                    }
                    if (StartOf(20)) {
                        if (la.val.ToLower().Equals("n")) {
                            Expect(22);
                            val += t.val;
                            if (la.kind == 24 || la.kind == 29) {
                                if (la.kind == 29) {
                                    Get();
                                    val += t.val;
                                } else {
                                    Get();
                                    val += t.val;
                                }
                                Expect(3);
                                val += t.val;
                                while (la.kind == 3) {
                                    Get();
                                    val += t.val;
                                }
                            }
                        } else if (la.kind == 48) {
                            Get();
                            trm.Unit = Model.Unit.Percent;
                        } else {
                            if (IsUnit()) {
                                identity(out ident);
                                try {
                                    trm.Unit = (Model.Unit)Enum.Parse(typeof(Model.Unit), ident, true);
                                } catch {
                                    errors.SemErr(t.line, t.col, string.Format("Unrecognized unit '{0}'", ident));
                                }

                            }
                        }
                    }
                    trm.Value = val; trm.Type = Model.TermType.Number;
                } else SynErr(59);
            } else SynErr(60);
        }
예제 #4
0
        void term(out Model.Term trm)
        {
            trm = new Model.Term();
            string val = "";

            Model.Expression exp   = null;
            string           ident = null;

            if (la.kind == 7 || la.kind == 8)
            {
                QuotedString(out val);
                trm.Value = val; trm.Type = Model.TermType.String;
            }
            else if (la.kind == 9)
            {
                URI(out val);
                trm.Value = val; trm.Type = Model.TermType.Url;
            }
            else if (la.kind == 47)
            {
                Get();
                identity(out ident);
                trm.Value = "U\\" + ident; trm.Type = Model.TermType.Unicode;
            }
            else if (la.kind == 33)
            {
                HexValue(out val);
                trm.Value = val; trm.Type = Model.TermType.Hex;
            }
            else if (StartOf(15))
            {
                bool minus = false;
                if (la.kind == 24)
                {
                    Get();
                    minus = true;
                }
                if (StartOf(16))
                {
                    identity(out ident);
                    trm.Value = ident; trm.Type = Model.TermType.String;
                    if (minus)
                    {
                        trm.Value = "-" + trm.Value;
                    }
                    while (la.kind == 4)
                    {
                        Get();
                    }
                    if (StartOf(17))
                    {
                        while (la.kind == 34 || la.kind == 36 || la.kind == 43)
                        {
                            if (la.kind == 43)
                            {
                                Get();
                                trm.Value += t.val;
                                if (StartOf(18))
                                {
                                    if (la.kind == 43)
                                    {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                    if (la.kind == 24)
                                    {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                    identity(out ident);
                                    trm.Value += ident;
                                }
                                else if (la.kind == 33)
                                {
                                    HexValue(out val);
                                    trm.Value += val;
                                }
                                else if (StartOf(19))
                                {
                                    while (la.kind == 3)
                                    {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                    if (la.kind == 34)
                                    {
                                        Get();
                                        trm.Value += ".";
                                        while (la.kind == 3)
                                        {
                                            Get();
                                            trm.Value += t.val;
                                        }
                                    }
                                }
                                else
                                {
                                    SynErr(57);
                                }
                            }
                            else if (la.kind == 34)
                            {
                                Get();
                                trm.Value += t.val;
                                if (la.kind == 24)
                                {
                                    Get();
                                    trm.Value += t.val;
                                }
                                identity(out ident);
                                trm.Value += ident;
                            }
                            else
                            {
                                Get();
                                trm.Value += t.val;
                                while (la.kind == 4)
                                {
                                    Get();
                                }
                                if (la.kind == 24)
                                {
                                    Get();
                                    trm.Value += t.val;
                                }
                                if (StartOf(16))
                                {
                                    identity(out ident);
                                    trm.Value += ident;
                                }
                                else if (StartOf(19))
                                {
                                    while (la.kind == 3)
                                    {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                }
                                else
                                {
                                    SynErr(58);
                                }
                            }
                        }
                    }
                    if (la.kind == 10)
                    {
                        Get();
                        while (la.kind == 4)
                        {
                            Get();
                        }
                        expr(out exp);
                        Model.Function func = new Model.Function();
                        func.Name       = trm.Value;
                        func.Expression = exp;
                        trm.Value       = null;
                        trm.Function    = func;
                        trm.Type        = Model.TermType.Function;

                        while (la.kind == 4)
                        {
                            Get();
                        }
                        Expect(11);
                    }
                }
                else if (StartOf(15))
                {
                    if (la.kind == 29)
                    {
                        Get();
                        trm.Sign = '+';
                    }
                    if (minus)
                    {
                        trm.Sign = '-';
                    }
                    while (la.kind == 3)
                    {
                        Get();
                        val += t.val;
                    }
                    if (la.kind == 34)
                    {
                        Get();
                        val += t.val;
                        while (la.kind == 3)
                        {
                            Get();
                            val += t.val;
                        }
                    }
                    if (StartOf(20))
                    {
                        if (la.val.ToLower().Equals("n"))
                        {
                            Expect(22);
                            val += t.val;
                            if (la.kind == 24 || la.kind == 29)
                            {
                                if (la.kind == 29)
                                {
                                    Get();
                                    val += t.val;
                                }
                                else
                                {
                                    Get();
                                    val += t.val;
                                }
                                Expect(3);
                                val += t.val;
                                while (la.kind == 3)
                                {
                                    Get();
                                    val += t.val;
                                }
                            }
                        }
                        else if (la.kind == 48)
                        {
                            Get();
                            trm.Unit = Model.Unit.Percent;
                        }
                        else
                        {
                            if (IsUnit())
                            {
                                identity(out ident);
                                try {
                                    trm.Unit = (Model.Unit)Enum.Parse(typeof(Model.Unit), ident, true);
                                } catch {
                                    errors.SemErr(t.line, t.col, string.Format("Unrecognized unit '{0}'", ident));
                                }
                            }
                        }
                    }
                    trm.Value = val; trm.Type = Model.TermType.Number;
                }
                else
                {
                    SynErr(59);
                }
            }
            else
            {
                SynErr(60);
            }
        }
예제 #5
0
파일: Term.cs 프로젝트: xescrp/breinstormin
 private int GetRGBValue(Term t)
 {
     try {
         if (t.Unit.HasValue && t.Unit.Value == breinstormin.tools.web.css.Model.Unit.Percent)
         {
             return (int)(255f * float.Parse(t.Value) / 100f);
         }
         return int.Parse(t.Value);
     } catch {}
     return 0;
 }
예제 #6
0
파일: Term.cs 프로젝트: xescrp/breinstormin
 private int GetHueValue(Term t)
 {
     // 0 - 360
     try {
         return (int)(float.Parse(t.Value) * 255f / 360f);
     } catch {}
     return 0;
 }