Example #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;
 }
Example #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();
 }
Example #3
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();
 }
Example #4
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)
                {
                    HighlightingSpan poppedSpan = spanStack.Peek();
                    if (!poppedSpan.SpanColorIncludesEnd)
                    {
                        PopColor();                         // pop SpanColor
                    }
                    PushColor(poppedSpan.EndColor);
                    position = firstMatch.Index + firstMatch.Length;
                    PopColor();                     // pop EndColor
                    if (poppedSpan.SpanColorIncludesEnd)
                    {
                        PopColor();                         // pop SpanColor
                    }
                    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);
                    if (newSpan.SpanColorIncludesStart)
                    {
                        PushColor(newSpan.SpanColor);
                    }
                    PushColor(newSpan.StartColor);
                    position = firstMatch.Index + firstMatch.Length;
                    PopColor();
                    if (!newSpan.SpanColorIncludesStart)
                    {
                        PushColor(newSpan.SpanColor);
                    }
                }
                endSpanMatch = null;
            }
            HighlightNonSpans(line.Length);

            PopAllColors();
        }
Example #5
0
 public TextLayerDocumentHighlighter(HighlightingColorizer colorizer, TextLayer textLayer, HighlightingRuleSet baseRuleSet)
     : base(textLayer.Document, baseRuleSet)
 {
     Debug.Assert(colorizer != null);
     Debug.Assert(textLayer != null);
     this.colorizer = colorizer;
     this.textLayer = textLayer;
 }
Example #6
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;
 }
Example #7
0
 public TextLayerDocumentHighlighter(HighlightingColorizer colorizer, TextLayer textLayer, HighlightingRuleSet baseRuleSet)
     : base(textLayer.Document, baseRuleSet)
 {
     Debug.Assert(colorizer != null);
     Debug.Assert(textLayer != null);
     this.colorizer = colorizer;
     this.textLayer = textLayer;
 }