コード例 #1
0
        public void FillRichEdit(System.Windows.Forms.RichTextBox rich, string value)
        {
            rich.Text = "";
            Line      = value;

            RTFBuilder sb = new RTFBuilder {
                BackColor = rich.BackColor
            };

            while (TokenId != TokenKind.tkNull)
            {
                Color forecolor;
                switch (TokenId)
                {
                case TokenKind.tkKey: forecolor = Color.Blue;
                    break;

                case TokenKind.tkFunction: forecolor = Color.Fuchsia; break;

                case TokenKind.tkGreyKeyword: forecolor = Color.Gray; break;

                case TokenKind.tkFuKeyword: forecolor = Color.Fuchsia; break;

                case TokenKind.tkDatatype: forecolor = Color.Blue; break;

                case TokenKind.tkNumber: forecolor = Color.Red; break;

                case TokenKind.tkString: forecolor = Color.Red; break;

                case TokenKind.tkComment: forecolor = Color.DarkGreen;
                    break;

                default: forecolor = Color.Black; break;
                }
                sb.ForeColor = forecolor;
                if (Token == Environment.NewLine || Token == "\r" || Token == "\n")
                {
                    sb.AppendLine();
                }
                else
                {
                    sb.Append(Token);
                }
                Next();
            }
            rich.Rtf = sb.ToString();
        }
コード例 #2
0
ファイル: YukonLexer.cs プロジェクト: w8tcha/expressprofiler
        public void FillRichEdit(RichTextBox rich, string value)
        {
            rich.Text = string.Empty;
            this.Line = value;

            var sb = new RTFBuilder {
                BackColor = rich.BackColor
            };

            while (this.TokenId != TokenKind.tkNull)
            {
                var forecolor = this.TokenId switch
                {
                    TokenKind.tkKey => Color.Blue,
                    TokenKind.tkFunction => Color.Fuchsia,
                    TokenKind.tkGreyKeyword => Color.Gray,
                    TokenKind.tkFuKeyword => Color.Fuchsia,
                    TokenKind.tkDatatype => Color.Blue,
                    TokenKind.tkNumber => Color.Red,
                    TokenKind.tkString => Color.Red,
                    TokenKind.tkComment => Color.DarkGreen,
                    _ => Color.Black
                };

                sb.ForeColor = forecolor;
                if (this.Token == Environment.NewLine || this.Token == "\r" || this.Token == "\n")
                {
                    sb.AppendLine();
                }
                else
                {
                    sb.Append(this.Token);
                }

                this.Next();
            }

            rich.Rtf = sb.ToString();
        }
        public void FillRichEdit(System. Windows.Forms.RichTextBox rich, string value)
        {

            rich.Text = "";
            Line = value;

            RTFBuilder sb = new RTFBuilder { BackColor = rich.BackColor };
            while (TokenId != TokenKind.tkNull)
            {
                Color forecolor;
                switch (TokenId)
                {
                    case TokenKind.tkKey: forecolor = Color.Blue;
                        break;
                    case TokenKind.tkFunction: forecolor = Color.Fuchsia; break;
                    case TokenKind.tkGreyKeyword: forecolor = Color.Gray; break;
                    case TokenKind.tkFuKeyword: forecolor = Color.Fuchsia; break;
                    case TokenKind.tkDatatype: forecolor = Color.Blue; break;
                    case TokenKind.tkNumber: forecolor = Color.Red; break;
                    case TokenKind.tkString: forecolor = Color.Red; break;
                    case TokenKind.tkComment: forecolor = Color.DarkGreen;
                        break;
                    default: forecolor = Color.Black; break;
                }
                sb.ForeColor = forecolor;
                if (Token == Environment.NewLine || Token == "\r" || Token == "\n")
                {
                    sb.AppendLine();
                }
                else
                {
                    sb.Append(Token);
                }
                Next();
            }
            rich.Rtf = sb.ToString();
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: ogvolkov/expressprofiler
        private void FillRichEdit(System.Windows.Forms.RichTextBox rich, IEnumerable<Token> tokens)
        {
            rich.Text = "";

            RTFBuilder sb = new RTFBuilder { BackColor = rich.BackColor };

            foreach (var token in tokens)
            {
                Color forecolor;
                switch (token.Kind)
                {
                    case YukonLexer.TokenKind.tkKey: forecolor = Color.Blue;
                        break;
                    case YukonLexer.TokenKind.tkFunction: forecolor = Color.Fuchsia; break;
                    case YukonLexer.TokenKind.tkGreyKeyword: forecolor = Color.Gray; break;
                    case YukonLexer.TokenKind.tkFuKeyword: forecolor = Color.Fuchsia; break;
                    case YukonLexer.TokenKind.tkDatatype: forecolor = Color.Blue; break;
                    case YukonLexer.TokenKind.tkNumber: forecolor = Color.Red; break;
                    case YukonLexer.TokenKind.tkString: forecolor = Color.Red; break;
                    case YukonLexer.TokenKind.tkComment: forecolor = Color.DarkGreen;
                        break;
                    default: forecolor = Color.Black; break;
                }
                sb.ForeColor = forecolor;
                if (token.Text == Environment.NewLine || token.Text == "\r" || token.Text == "\n")
                {
                    sb.AppendLine();
                }
                else
                {
                    sb.Append(token.Text);
                }
            }
            rich.Rtf = sb.ToString();
        }
コード例 #5
0
        public void FillRichEdit(System.Windows.Forms.RichTextBox rich, string value)
        {
            rich.Text = "";
            Line      = value;


            System.Collections.Generic.List <TokenKind> lsTokenTypeHistory =
                new System.Collections.Generic.List <TokenKind>();


            RTFBuilder sb = new RTFBuilder {
                BackColor = rich.BackColor
            };

            while (TokenId != TokenKind.tkNull)
            {
                if (TokenId != TokenKind.tkSpace)
                {
                    lsTokenTypeHistory.Add(TokenId);
                }

                Color forecolor;
                switch (TokenId)
                {
                case TokenKind.tkKey:
                    forecolor = Color.Blue;
                    break;

                case TokenKind.tkFunction: forecolor = Color.Fuchsia; break;

                case TokenKind.tkGreyKeyword: forecolor = Color.Gray; break;

                case TokenKind.tkFuKeyword: forecolor = Color.Fuchsia; break;

                case TokenKind.tkDatatype:
                    forecolor = Color.Blue; break;

                case TokenKind.tkNumber: forecolor = Color.Red; break;

                case TokenKind.tkString: forecolor = Color.Red; break;

                case TokenKind.tkComment:
                    forecolor = Color.DarkGreen;
                    break;

                default: forecolor = Color.Black; break;
                }
                sb.ForeColor = forecolor;

                if (Token == Environment.NewLine || Token == "\n")
                {
                    sb.AppendLine();
                }
                else if (Token != "\r")
                {
                    int cntHistory = lsTokenTypeHistory.Count;

                    // If the token has a datetime parameter-value that is passed as string,
                    // ensure yyyy-MM-dd' 'HH:mm:ss[.fff] is replaced with yyyy-MM-dd'T'HH:mm:ss[.fff]
                    if (TokenKind.tkString == TokenId &&
                        cntHistory > 3 &&
                        lsTokenTypeHistory[cntHistory - 2] == TokenKind.tkSymbol &&
                        lsTokenTypeHistory[cntHistory - 3] == TokenKind.tkVariable &&
                        System.Text.RegularExpressions.Regex
                        .IsMatch(
                            Token
                            , @"^'\d\d\d\d-\d\d-\d\d\s\d\d\:\d\d\:\d\d(\.\d\d\d)?'$"
                            , System.Text.RegularExpressions.RegexOptions.Compiled
                            )
                        )
                    {
                        // System.DateTime dt;
                        // if (System.DateTime.TryParseExact(Token, "yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out dt))
                        // sb.Append(dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff"));
                        sb.Append(Token.Replace(" ", "T"));
                    }
                    else
                    {
                        sb.Append(Token);
                    }
                }
                Next();
            }

            lsTokenTypeHistory.Clear();
            lsTokenTypeHistory = null;

            rich.Rtf = sb.ToString();
        }