コード例 #1
0
 /// <summary>
 /// Creates a new HighlightingColorizer instance.
 /// </summary>
 /// <param name="ruleSet">The root highlighting rule set.</param>
 public HighlightingColorizer(HighlightingRuleSet ruleSet)
 {
     if (ruleSet == null)
     {
         throw new ArgumentNullException("ruleSet");
     }
     this.ruleSet = ruleSet;
 }
コード例 #2
0
 /// <summary>
 /// Creates a new DocumentHighlighter instance.
 /// </summary>
 public DocumentHighlighter(TextDocument document, HighlightingRuleSet baseRuleSet)
 {
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     if (baseRuleSet == null)
     {
         throw new ArgumentNullException("baseRuleSet");
     }
     this.document    = document;
     this.baseRuleSet = baseRuleSet;
     WeakLineTracker.Register(document, this);
     InvalidateHighlighting();
 }
コード例 #3
0
        void HighlightLineInternal(DocumentLine line)
        {
            lineStartOffset = line.Offset;
            lineText        = document.GetText(line.Offset, line.Length);
            position        = 0;
            ResetColorStack();
            HighlightingRuleSet currentRuleSet    = this.CurrentRuleSet;
            Stack <Match[]>     storedMatchArrays = new Stack <Match[]>();

            Match[] matches      = AllocateMatchArray(currentRuleSet.Spans.Count);
            Match   endSpanMatch = null;

            while (true)
            {
                for (int i = 0; i < matches.Length; i++)
                {
                    if (matches[i] == null || (matches[i].Success && matches[i].Index < position))
                    {
                        matches[i] = currentRuleSet.Spans[i].StartExpression.Match(lineText, position);
                    }
                }
                if (endSpanMatch == null && !spanStack.IsEmpty)
                {
                    endSpanMatch = spanStack.Peek().EndExpression.Match(lineText, position);
                }

                Match firstMatch = Minimum(matches, endSpanMatch);
                if (firstMatch == null)
                {
                    break;
                }

                HighlightNonSpans(firstMatch.Index);

                Debug.Assert(position == firstMatch.Index);

                if (firstMatch == endSpanMatch)
                {
                    PopColor();                     // pop SpanColor
                    HighlightingSpan poppedSpan = spanStack.Peek();
                    PushColor(poppedSpan.EndColor);
                    position = firstMatch.Index + firstMatch.Length;
                    PopColor();                     // pop EndColor
                    spanStack      = spanStack.Pop();
                    currentRuleSet = this.CurrentRuleSet;
                    //FreeMatchArray(matches);
                    if (storedMatchArrays.Count > 0)
                    {
                        matches = storedMatchArrays.Pop();
                        int index = currentRuleSet.Spans.IndexOf(poppedSpan);
                        Debug.Assert(index >= 0 && index < matches.Length);
                        if (matches[index].Index == position)
                        {
                            throw new InvalidOperationException(
                                      "A highlighting span matched 0 characters, which would cause an endless loop.\n" +
                                      "Change the highlighting definition so that either the start or the end regex matches at least one character.\n" +
                                      "Start regex: " + poppedSpan.StartExpression + "\n" +
                                      "End regex: " + poppedSpan.EndExpression);
                        }
                    }
                    else
                    {
                        matches = AllocateMatchArray(currentRuleSet.Spans.Count);
                    }
                }
                else
                {
                    int index = Array.IndexOf(matches, firstMatch);
                    Debug.Assert(index >= 0);
                    HighlightingSpan newSpan = currentRuleSet.Spans[index];
                    spanStack      = spanStack.Push(newSpan);
                    currentRuleSet = this.CurrentRuleSet;
                    storedMatchArrays.Push(matches);
                    matches = AllocateMatchArray(currentRuleSet.Spans.Count);
                    PushColor(newSpan.StartColor);
                    position = firstMatch.Index + firstMatch.Length;
                    PopColor();
                    PushColor(newSpan.SpanColor);
                }
                endSpanMatch = null;
            }
            HighlightNonSpans(line.Length);

            PopAllColors();
        }
コード例 #4
0
 public HighlightingColorizer(TextView textView, HighlightingRuleSet ruleSet)
     : this(ruleSet)
 {
 }
コード例 #5
0
 public TextViewDocumentHighlighter(TextView textView, TextDocument document, HighlightingRuleSet baseRuleSet)
     : base(document, baseRuleSet)
 {
     Debug.Assert(textView != null);
     this.textView = textView;
 }