Beispiel #1
0
    internal override void RenderCode(CodeRender cr, Node n, Node nparent)
    {
        const double operatorscale = 1.3;
        string       altop         = null;

        switch (name)
        {
        case "!=": altop = "\u2260"; break;

        case "<=": altop = "\u2264"; break;

        case ">=": altop = "\u2265"; break;

        case "==": altop = "\u2A75"; break;

        case "*": altop = "\u2A2F"; break;

        case "/": altop = "\u00F7"; break;

        case "!": altop = "\u00AC"; break;

        case "|>": altop = "\u22B3"; break;
        }

        if (NeedsParens(nparent, n))
        {
            cr.Text("(", 0, Program.bracketspacing);
        }

        if (name == "__apply")
        {
            n.At(0).RenderCode(cr, n);
            cr.Scale(operatorscale, () => cr.Text("!", 0, 0));
            if (n.Arity() > 1)
            {
                n.RenderCodeChildren(cr, "(", ")", 1);
            }
        }
        else if (name == "|>")
        {
            n.At(1).RenderCode(cr, n);
            cr.AltNext(altop);
            cr.Scale(operatorscale,
                     () => cr.Text("|>", Program.operatorspacing, Program.operatorspacing));
            n.At(0).RenderCode(cr, n);
        }
        else if (name == "__list")
        {
            n.RenderCodeChildren(cr, "[", "]");
        }
        else if (n.Arity() == 1)
        {
            cr.AltNext(altop);
            cr.Scale(operatorscale,
                     () => cr.Text(name, Program.operatorspacing, Program.operatorspacing));
            n.At(0).RenderCode(cr, n);
        }
        else if (n.Arity() == 2)
        {
            n.At(name == "=" ? 1 : 0).RenderCode(cr, n);
            cr.AltNext(altop);
            cr.Scale(operatorscale,
                     () => cr.Text(name, Program.operatorspacing, Program.operatorspacing));
            n.At(name == "=" ? 0 : 1).RenderCode(cr, n);
        }
        else
        {
            Debug.Assert(false);
        }

        if (NeedsParens(nparent, n))
        {
            cr.Text(")", Program.bracketspacing, 0);
        }
    }