コード例 #1
0
ファイル: TextWord.cs プロジェクト: zhangxsheng/Codematic
 public TabTextWord(HighlightColor color)
 {
     this.length = 1;
     this.color  = color;
 }
コード例 #2
0
ファイル: TextWord.cs プロジェクト: zhangxsheng/Codematic
 public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
 {
     this.document        = document;
     this.line            = line;
     this.offset          = offset;
     this.length          = length;
     this.color           = color;
     this.hasDefaultColor = hasDefaultColor;
 }
コード例 #3
0
 private void PushCurWord(IDocument document, ref HighlightColor markNext, ArrayList words)
 {
     if (this.currentLength > 0)
     {
         if (words.Count > 0 && this.activeRuleSet != null)
         {
             int i = words.Count - 1;
             while (i >= 0)
             {
                 if (!((TextWord)words[i]).IsWhiteSpace)
                 {
                     TextWord textWord = (TextWord)words[i];
                     if (!textWord.HasDefaultColor)
                     {
                         break;
                     }
                     PrevMarker prevMarker = (PrevMarker)this.activeRuleSet.PrevMarkers[document, this.currentLine, this.currentOffset, this.currentLength];
                     if (prevMarker != null)
                     {
                         textWord.SyntaxColor = prevMarker.Color;
                         break;
                     }
                     break;
                 }
                 else
                 {
                     i--;
                 }
             }
         }
         if (this.inSpan)
         {
             bool           hasDefaultColor = true;
             HighlightColor highlightColor;
             if (this.activeSpan.Rule == null)
             {
                 highlightColor = this.activeSpan.Color;
             }
             else
             {
                 highlightColor  = this.GetColor(this.activeRuleSet, document, this.currentLine, this.currentOffset, this.currentLength);
                 hasDefaultColor = false;
             }
             if (highlightColor == null)
             {
                 highlightColor = this.activeSpan.Color;
                 if (highlightColor.Color == Color.Transparent)
                 {
                     highlightColor = this.GetColorFor("Default");
                 }
                 hasDefaultColor = true;
             }
             words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, (markNext != null) ? markNext : highlightColor, hasDefaultColor));
         }
         else
         {
             HighlightColor highlightColor2 = (markNext != null) ? markNext : this.GetColor(this.activeRuleSet, document, this.currentLine, this.currentOffset, this.currentLength);
             if (highlightColor2 == null)
             {
                 words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, this.GetColorFor("Default"), true));
             }
             else
             {
                 words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, highlightColor2, false));
             }
         }
         if (this.activeRuleSet != null)
         {
             NextMarker nextMarker = (NextMarker)this.activeRuleSet.NextMarkers[document, this.currentLine, this.currentOffset, this.currentLength];
             if (nextMarker != null)
             {
                 if (nextMarker.MarkMarker && words.Count > 0)
                 {
                     TextWord textWord2 = (TextWord)words[words.Count - 1];
                     textWord2.SyntaxColor = nextMarker.Color;
                 }
                 markNext = nextMarker.Color;
             }
             else
             {
                 markNext = null;
             }
         }
         this.currentOffset += this.currentLength;
         this.currentLength  = 0;
     }
 }
コード例 #4
0
        private ArrayList ParseLine(IDocument document)
        {
            ArrayList      arrayList      = new ArrayList();
            HighlightColor highlightColor = null;

            this.currentOffset = 0;
            this.currentLength = 0;
            this.UpdateSpanStateVariables();
            int i = 0;

            while (i < this.currentLine.Length)
            {
                char charAt = document.GetCharAt(this.currentLine.Offset + i);
                char c      = charAt;
                switch (c)
                {
                case '\t':
                    this.PushCurWord(document, ref highlightColor, arrayList);
                    if (this.activeSpan != null && this.activeSpan.Color.HasBackground)
                    {
                        arrayList.Add(new TextWord.TabTextWord(this.activeSpan.Color));
                    }
                    else
                    {
                        arrayList.Add(TextWord.Tab);
                    }
                    this.currentOffset++;
                    break;

                case '\n':
                case '\r':
                    this.PushCurWord(document, ref highlightColor, arrayList);
                    this.currentOffset++;
                    break;

                case '\v':
                case '\f':
                    goto IL_1AA;

                default:
                    if (c != ' ')
                    {
                        if (c != '\\')
                        {
                            goto IL_1AA;
                        }
                        if ((this.activeRuleSet != null && this.activeRuleSet.NoEscapeSequences) || (this.activeSpan != null && this.activeSpan.NoEscapeSequences))
                        {
                            goto IL_1AA;
                        }
                        this.currentLength++;
                        if (i + 1 < this.currentLine.Length)
                        {
                            this.currentLength++;
                        }
                        this.PushCurWord(document, ref highlightColor, arrayList);
                        i++;
                    }
                    else
                    {
                        this.PushCurWord(document, ref highlightColor, arrayList);
                        if (this.activeSpan != null && this.activeSpan.Color.HasBackground)
                        {
                            arrayList.Add(new TextWord.SpaceTextWord(this.activeSpan.Color));
                        }
                        else
                        {
                            arrayList.Add(TextWord.Space);
                        }
                        this.currentOffset++;
                    }
                    break;
                }
IL_83E:
                i++;
                continue;
IL_1AA:
                if (!this.inSpan && (char.IsDigit(charAt) || (charAt == '.' && i + 1 < this.currentLine.Length && char.IsDigit(document.GetCharAt(this.currentLine.Offset + i + 1)))) && this.currentLength == 0)
                {
                    bool flag  = false;
                    bool flag2 = false;
                    if (charAt == '0' && i + 1 < this.currentLine.Length && char.ToUpper(document.GetCharAt(this.currentLine.Offset + i + 1)) == 'X')
                    {
                        this.currentLength++;
                        i++;
                        this.currentLength++;
                        flag = true;
                        while (i + 1 < this.currentLine.Length)
                        {
                            if ("0123456789ABCDEF".IndexOf(char.ToUpper(document.GetCharAt(this.currentLine.Offset + i + 1))) == -1)
                            {
                                break;
                            }
                            i++;
                            this.currentLength++;
                        }
                    }
                    else
                    {
                        this.currentLength++;
                        while (i + 1 < this.currentLine.Length && char.IsDigit(document.GetCharAt(this.currentLine.Offset + i + 1)))
                        {
                            i++;
                            this.currentLength++;
                        }
                    }
                    if (!flag && i + 1 < this.currentLine.Length && document.GetCharAt(this.currentLine.Offset + i + 1) == '.')
                    {
                        flag2 = true;
                        i++;
                        this.currentLength++;
                        while (i + 1 < this.currentLine.Length && char.IsDigit(document.GetCharAt(this.currentLine.Offset + i + 1)))
                        {
                            i++;
                            this.currentLength++;
                        }
                    }
                    if (i + 1 < this.currentLine.Length && char.ToUpper(document.GetCharAt(this.currentLine.Offset + i + 1)) == 'E')
                    {
                        flag2 = true;
                        i++;
                        this.currentLength++;
                        if (i + 1 < this.currentLine.Length && (document.GetCharAt(this.currentLine.Offset + i + 1) == '+' || document.GetCharAt(this.currentLine.Offset + i + 1) == '-'))
                        {
                            i++;
                            this.currentLength++;
                        }
                        while (i + 1 < this.currentLine.Length && char.IsDigit(document.GetCharAt(this.currentLine.Offset + i + 1)))
                        {
                            i++;
                            this.currentLength++;
                        }
                    }
                    if (i + 1 < this.currentLine.Length)
                    {
                        char c2 = char.ToUpper(document.GetCharAt(this.currentLine.Offset + i + 1));
                        if (c2 == 'F' || c2 == 'M' || c2 == 'D')
                        {
                            flag2 = true;
                            i++;
                            this.currentLength++;
                        }
                    }
                    if (!flag2)
                    {
                        bool flag3 = false;
                        if (i + 1 < this.currentLine.Length && char.ToUpper(document.GetCharAt(this.currentLine.Offset + i + 1)) == 'U')
                        {
                            i++;
                            this.currentLength++;
                            flag3 = true;
                        }
                        if (i + 1 < this.currentLine.Length && char.ToUpper(document.GetCharAt(this.currentLine.Offset + i + 1)) == 'L')
                        {
                            i++;
                            this.currentLength++;
                            if (!flag3 && i + 1 < this.currentLine.Length && char.ToUpper(document.GetCharAt(this.currentLine.Offset + i + 1)) == 'U')
                            {
                                i++;
                                this.currentLength++;
                            }
                        }
                    }
                    arrayList.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, this.DigitColor, false));
                    this.currentOffset += this.currentLength;
                    this.currentLength  = 0;
                    goto IL_83E;
                }
                if (this.inSpan && this.activeSpan.End != null && !this.activeSpan.End.Equals("") && this.currentLine.MatchExpr(this.activeSpan.End, i, document))
                {
                    this.PushCurWord(document, ref highlightColor, arrayList);
                    string regString = this.currentLine.GetRegString(this.activeSpan.End, i, document);
                    this.currentLength += regString.Length;
                    arrayList.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, this.activeSpan.EndColor, false));
                    this.currentOffset += this.currentLength;
                    this.currentLength  = 0;
                    i += regString.Length - 1;
                    this.currentSpanStack.Pop();
                    this.UpdateSpanStateVariables();
                    goto IL_83E;
                }
                if (this.activeRuleSet != null)
                {
                    foreach (Span span in this.activeRuleSet.Spans)
                    {
                        if (this.currentLine.MatchExpr(span.Begin, i, document))
                        {
                            this.PushCurWord(document, ref highlightColor, arrayList);
                            string regString2 = this.currentLine.GetRegString(span.Begin, i, document);
                            this.currentLength += regString2.Length;
                            arrayList.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, span.BeginColor, false));
                            this.currentOffset += this.currentLength;
                            this.currentLength  = 0;
                            i += regString2.Length - 1;
                            if (this.currentSpanStack == null)
                            {
                                this.currentSpanStack = new Stack();
                            }
                            this.currentSpanStack.Push(span);
                            this.UpdateSpanStateVariables();
                            goto IL_83E;
                        }
                    }
                }
                if (this.activeRuleSet != null && charAt < 'Ā' && this.activeRuleSet.Delimiters[(int)charAt])
                {
                    this.PushCurWord(document, ref highlightColor, arrayList);
                    if (this.currentOffset + this.currentLength + 1 < this.currentLine.Length)
                    {
                        this.currentLength++;
                        this.PushCurWord(document, ref highlightColor, arrayList);
                        goto IL_83E;
                    }
                }
                this.currentLength++;
                goto IL_83E;
            }
            this.PushCurWord(document, ref highlightColor, arrayList);
            return(arrayList);
        }
コード例 #5
0
 internal void SetColorFor(string name, HighlightColor color)
 {
     this.environmentColors[name] = color;
 }
コード例 #6
0
 public HighlightColor(XmlElement el, HighlightColor defaultColor)
 {
     if (el.Attributes["bold"] != null)
     {
         this.bold = bool.Parse(el.Attributes["bold"].InnerText);
     }
     else
     {
         this.bold = defaultColor.Bold;
     }
     if (el.Attributes["italic"] != null)
     {
         this.italic = bool.Parse(el.Attributes["italic"].InnerText);
     }
     else
     {
         this.italic = defaultColor.Italic;
     }
     if (el.Attributes["color"] != null)
     {
         string innerText = el.Attributes["color"].InnerText;
         if (innerText[0] == '#')
         {
             this.color = HighlightColor.ParseColor(innerText);
         }
         else
         {
             if (innerText.StartsWith("SystemColors."))
             {
                 this.systemColor     = true;
                 this.systemColorName = innerText.Substring("SystemColors.".Length);
             }
             else
             {
                 this.color = (Color)this.Color.GetType().InvokeMember(innerText, BindingFlags.GetProperty, null, this.Color, new object[0]);
             }
         }
         this.hasForgeground = true;
     }
     else
     {
         this.color = defaultColor.color;
     }
     if (el.Attributes["bgcolor"] != null)
     {
         string innerText2 = el.Attributes["bgcolor"].InnerText;
         if (innerText2[0] == '#')
         {
             this.backgroundcolor = HighlightColor.ParseColor(innerText2);
         }
         else
         {
             if (innerText2.StartsWith("SystemColors."))
             {
                 this.systemBgColor     = true;
                 this.systemBgColorName = innerText2.Substring("SystemColors.".Length);
             }
             else
             {
                 this.backgroundcolor = (Color)this.Color.GetType().InvokeMember(innerText2, BindingFlags.GetProperty, null, this.Color, new object[0]);
             }
         }
         this.hasBackground = true;
         return;
     }
     this.backgroundcolor = defaultColor.BackgroundColor;
 }