private bool ColoriseRhoToken(RhoToken tok, Slice slice)
        {
            if (slice.Length < 0)
            {
                return(false);
            }

            bool Render(string color)
            => SetRhoSliceColor(slice, color, _defaultFont);

            bool RenderBold(string color)
            => SetRhoSliceColor(slice, color, _boldFont);

            var token = tok.Type;

            switch (token)
            {
            case ERhoToken.Assert:
            case ERhoToken.Fun:
            case ERhoToken.Class:
            case ERhoToken.Ident:
                return(RenderBold(GetTokenColor(token)));

            case ERhoToken.LessEquiv:
                return(Render("#707070"));

            case ERhoToken.String:
                // color the quotes too
                var expanded = new Slice(slice.Lexer, slice.LineNumber, slice.Start - 1, slice.End + 1);
                return(SetRhoSliceColor(expanded, "#FFA500", _boldFont));

            case ERhoToken.PiSlice:
                var expanded2 = new Slice(slice.Lexer, slice.LineNumber, slice.Start - 1, slice.End + 1);
                return(SetRhoSliceColor(expanded2, "#FFA5FF", _boldFont));

            default:
                return(Render(GetTokenColor(token)));
            }
        }
Exemplo n.º 2
0
        private bool ColoriseRhoToken(RhoToken tok, Slice slice)
        {
            if (slice.Length < 0)
            {
                return(false);
            }

            bool Render(Color color) => SetRhoSliceColor(slice, color, _defaultFont);
            bool RenderBold(Color color) => SetRhoSliceColor(slice, color, _boldFont);

            switch (tok.Type)
            {
            case ERhoToken.Assert:
                return(RenderBold(Color.DarkMagenta));

            case ERhoToken.Fun:
                return(RenderBold(Color.Black));

            case ERhoToken.Class:
                return(RenderBold(Color.DarkSlateGray));

            // operators
            case ERhoToken.Plus:
            case ERhoToken.Minus:
            case ERhoToken.Multiply:
            case ERhoToken.Divide:
            //case ERhoToken.Modulo:
            case ERhoToken.And:
            case ERhoToken.Or:
            case ERhoToken.Xor:
            case ERhoToken.Equiv:
            case ERhoToken.GreaterEquiv:
            case ERhoToken.Less:
            case ERhoToken.LessEquiv:
                return(Render(Color.SteelBlue));

            case ERhoToken.String:
                // color the quotes too
                var expanded = new Slice(slice.Lexer, slice.LineNumber, slice.Start - 1, slice.End + 1);
                return(SetRhoSliceColor(expanded, Color.Blue, _boldFont));

            case ERhoToken.Int:
                return(Render(Color.Brown));

            case ERhoToken.Float:
                return(Render(Color.Chocolate));

            case ERhoToken.Ident:
                return(RenderBold(Color.DarkSlateBlue));

            case ERhoToken.Quote:
                return(Render(Color.Gray));

            case ERhoToken.New:
            case ERhoToken.Delete:
                return(Render(Color.DarkOliveGreen));

            case ERhoToken.Comment:
                return(Render(Color.Gray));

            default:
                return(Render(DefaultForeColor));
            }
        }