Ejemplo n.º 1
0
        public string SyntaxHighlight(OutputWriter sb, string value)
        {
            Line = value;

            sb.AppendLine();

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

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

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

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

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

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

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

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

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

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

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

                if (Token == System.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();
            }

            sb.AppendLine();
            sb.AppendLine();

            lsTokenTypeHistory.Clear();
            lsTokenTypeHistory = null;

            return(sb.ToString());
        }