Example #1
0
            private void NormalSyntaxHighlight(Utoken utoken, UnparsableAst target, IDecoration decoration)
            {
                if (target.AstValue is D.Color && SpecialSyntaxHighlightForColorLiterals)
                {
                    Color color;

                    if (Enum.TryParse <Color>(target.AstValue.ToString(), out color))
                    {
                        decoration
                        .Add(DecorationKey.Background, color)
                        ;

                        if (color.EqualToAny(Color.Black, Color.Blue, Color.Green, Color.Red))
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.White)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Black)
                            ;
                        }
                    }
                }
                else if (utoken.Discriminator.EqualToAny(CommentContent, CommentStartSymbol, CommentEndSymbol))
                {
                    decoration
                    .Add(DecorationKey.Foreground, ForeColorOfComment)
                    ;
                }
                else if (target.BnfTerm is KeyTerm)
                {
                    if (target.BnfTerm.IsOperator() || target.BnfTerm.IsBrace())
                    {
                        decoration
                        .Add(DecorationKey.Foreground, ForeColorOfOperator)
                        ;
                    }
                    else
                    {
                        decoration
                        .Add(DecorationKey.Foreground, ForeColorOfKeyword)
                        ;
                    }
                }
                else if (target.AstValue is D.Type)
                {
                    decoration
                    .Add(DecorationKey.Foreground, ForeColorOfType)
                    ;
                }
                else if (target.BnfTerm.IsLiteral() || target.BnfTerm.IsConstant())
                {
                    decoration
                    .Add(DecorationKey.Foreground, ForeColorOfLiteral)
                    ;
                }
            }
Example #2
0
 private void NormalSyntaxHighlight(Utoken utoken, UnparsableAst target, IDecoration decoration)
 {
     if (target.BnfTerm is KeyTerm)
     {
         decoration
         .Add(DecorationKey.Foreground, ForeColorOfOperator)
         ;
     }
     else if (target.BnfTerm.IsLiteral() || target.BnfTerm.IsConstant())
     {
         decoration
         .Add(DecorationKey.Foreground, ForeColorOfLiteral)
         ;
     }
 }
Example #3
0
            private void CrazySyntaxHighlight(Utoken utoken, UnparsableAst target, IDecoration decoration)
            {
                if (target.AstValue is D.Color)
                {
                    Color color;

                    if (Enum.TryParse <Color>(target.AstValue.ToString(), out color))
                    {
                        decoration
                        .Add(DecorationKey.Background, color)
                        ;

                        if (color.EqualToAny(Color.Black, Color.Blue, Color.Green, Color.Red))
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.White)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Black)
                            ;
                        }
                    }
                }
                else if (utoken.Discriminator == CommentContent)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Pink)
                    .Add(DecorationKey.TextDecoration, TextDecoration.Strikethrough)
                    .Add(DecorationKey.FontStyle, FontStyle.Italic)
                    ;
                }
                else if (utoken.Discriminator == CommentStartSymbol)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Yellow)
                    .Add(DecorationKey.Background, Color.Violet)
                    ;
                }
                else if (utoken.Discriminator == CommentEndSymbol)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Blue)
                    .Add(DecorationKey.Background, Color.Yellow)
                    ;
                }
                else if (utoken.Discriminator == StringLiteralStartSymbol)
                {
                    decoration
                    .Add(DecorationKey.FontSizeRelativePercent, 2)
                    .Add(DecorationKey.Foreground, Color.Red)
                    .Add(DecorationKey.Background, Color.Blue)
                    ;
                }
                else if (target.AstValue is D.If)
                {
                    if (target.BnfTerm == B.LEFT_PAREN)
                    {
                        decoration
                        .Add(DecorationKey.FontWeight, FontWeight.Bold)
                        .Add(DecorationKey.FontSizeRelativePercent, 2)
                        .Add(DecorationKey.Foreground, Color.Blue)
                        ;
                    }
                    else
                    {
                        decoration
                        .Add(DecorationKey.FontWeight, FontWeight.Bold)
                        .Add(DecorationKey.TextDecoration, TextDecoration.Underline)
                        ;
                    }
                }
                else if (target.BnfTerm == B.PROGRAM)
                {
                    decoration
                    .Add(DecorationKey.FontStyle, FontStyle.Italic)
                    .Add(DecorationKey.Foreground, Color.Red)
                    .Add(DecorationKey.Background, Color.Yellow)
                    .Add(DecorationKey.FontSize, 30);
                }
                else if (target.AstValue is D.Type)
                {
                    decoration
                    .Add(DecorationKey.BaselineAlignment, BaselineAlignment.Subscript)
                    .Add(DecorationKey.FontSizeRelativePercent, 0.75);
                }
                else if (target.AstValue is INumberLiteral)
                {
                    INumberLiteral number = (INumberLiteral)target.AstValue;

                    if (number.Value is int)
                    {
                        if (((int)number.Value) % 2 == 0)
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Red)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Green)
                            .Add(DecorationKey.Background, Color.Yellow)
                            ;
                        }
                    }
                }
            }