Ejemplo n.º 1
0
        /// <summary>
        /// pushes the curWord string on the word list, with the correct color.
        /// </summary>
        void PushCurWord(Document document, ref HighlightColor markNext, List <TextWord> words)
        {
            // Svante Lidman : Need to look through the next prev logic.
            if (_currentLength > 0)
            {
                if (words.Count > 0 && _activeRuleSet != null)
                {
                    TextWord prevWord = null;
                    int      pInd     = words.Count - 1;
                    while (pInd >= 0)
                    {
                        if (!words[pInd].IsWhiteSpace)
                        {
                            prevWord = (TextWord)words[pInd];
                            if (prevWord.HasDefaultColor)
                            {
                                AdjacentMarker marker = (AdjacentMarker)_activeRuleSet.PrevMarkers[document, _currentLine, _currentOffset, _currentLength];
                                if (marker != null)
                                {
                                    prevWord.SyntaxColor = marker.Color;
                                    //									document.Caret.ValidateCaretPos();
                                    //									document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
                                }
                            }
                            break;
                        }
                        pInd--;
                    }
                }

                if (_inSpan)
                {
                    HighlightColor c = null;
                    bool           hasDefaultColor = true;
                    if (_activeSpan.Rule == null)
                    {
                        c = _activeSpan.Color;
                    }
                    else
                    {
                        c = GetColor(_activeRuleSet, document, _currentLine, _currentOffset, _currentLength);
                        hasDefaultColor = false;
                    }

                    if (c == null)
                    {
                        c = _activeSpan.Color;
                        if (c.Color == Color.Transparent)
                        {
                            c = DefaultTextColor;
                        }
                        hasDefaultColor = true;
                    }
                    words.Add(new TextWord(document, _currentLine, _currentOffset, _currentLength, markNext != null ? markNext : c, hasDefaultColor));
                }
                else
                {
                    HighlightColor c = markNext != null ? markNext : GetColor(_activeRuleSet, document, _currentLine, _currentOffset, _currentLength);
                    if (c == null)
                    {
                        words.Add(new TextWord(document, _currentLine, _currentOffset, _currentLength, DefaultTextColor, true));
                    }
                    else
                    {
                        words.Add(new TextWord(document, _currentLine, _currentOffset, _currentLength, c, false));
                    }
                }

                if (_activeRuleSet != null)
                {
                    AdjacentMarker nextMarker = (AdjacentMarker)_activeRuleSet.NextMarkers[document, _currentLine, _currentOffset, _currentLength];
                    if (nextMarker != null)
                    {
                        if (nextMarker.MarkMarker && words.Count > 0)
                        {
                            TextWord prevword = ((TextWord)words[words.Count - 1]);
                            prevword.SyntaxColor = nextMarker.Color;
                        }
                        markNext = nextMarker.Color;
                    }
                    else
                    {
                        markNext = null;
                    }
                }
                _currentOffset += _currentLength;
                _currentLength  = 0;
            }
        }
        public HighlightRuleSet(XmlElement el)
        {
            XmlNodeList nodes;

            if (el.Attributes["name"] != null)
            {
                Name = el.Attributes["name"].InnerText;
            }

            if (el.HasAttribute("escapecharacter"))
            {
                EscapeCharacter = el.GetAttribute("escapecharacter")[0];
            }

            if (el.Attributes["reference"] != null)
            {
                Reference = el.Attributes["reference"].InnerText;
            }

            if (el.Attributes["ignorecase"] != null)
            {
                IgnoreCase = Boolean.Parse(el.Attributes["ignorecase"].InnerText);
            }

            for (int i = 0; i < Delimiters.Length; ++i)
            {
                Delimiters[i] = false;
            }

            if (el["Delimiters"] != null)
            {
                string delimiterString = el["Delimiters"].InnerText;
                foreach (char ch in delimiterString)
                {
                    Delimiters[(int)ch] = true;
                }
            }

//			Spans       = new LookupTable(!IgnoreCase);

            KeyWords    = new LookupTable(!IgnoreCase);
            PrevMarkers = new LookupTable(!IgnoreCase);
            NextMarkers = new LookupTable(!IgnoreCase);

            nodes = el.GetElementsByTagName("KeyWords");
            foreach (XmlElement el2 in nodes)
            {
                HighlightColor color = new HighlightColor(el2);

                XmlNodeList keys = el2.GetElementsByTagName("Key");
                foreach (XmlElement node in keys)
                {
                    KeyWords[node.Attributes["word"].InnerText] = color;
                }
            }

            nodes = el.GetElementsByTagName("Span");
            foreach (XmlElement el2 in nodes)
            {
                Spans.Add(new Span(el2));

                /*
                 * Span span = new Span(el2);
                 * Spans[span.Begin] = span;*/
            }

            nodes = el.GetElementsByTagName("MarkPrevious");
            foreach (XmlElement el2 in nodes)
            {
                AdjacentMarker prev = new AdjacentMarker(el2);
                PrevMarkers[prev.What] = prev;
            }

            nodes = el.GetElementsByTagName("MarkFollowing");
            foreach (XmlElement el2 in nodes)
            {
                AdjacentMarker next = new AdjacentMarker(el2);
                NextMarkers[next.What] = next;
            }
        }