示例#1
0
        static string Render(Model.Function func)
        {
            StringBuilder txt = new StringBuilder();

            txt.AppendFormat("<span class=\"function_name\">{0}</span>(", func.Name);
            txt.AppendFormat("<span class=\"expression\">{0}</span>", Render(func.Expression));
            //if (expression != null) {
            //    bool first = true;
            //    foreach (Term t in expression.Terms) {
            //        txt.Append(t.ToString());
            //    }
            //}
            txt.Append(")");

            return(txt.ToString());
        }
示例#2
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);
        }
示例#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);
            }
        }