/// <summary> /// Creates a new instance of <see cref="PrevMarker"/> /// </summary> public PrevMarker(XmlElement mark) { color = new HighlightColor(mark); what = mark.InnerText; if (mark.Attributes["markmarker"] != null) { markMarker = Boolean.Parse(mark.Attributes["markmarker"].InnerText); } }
protected void ImportSettingsFrom(DefaultHighlightingStrategy source) { if (source == null) throw new ArgumentNullException("source"); mProperties = source.mProperties; extensions = source.extensions; mDigitColor = source.mDigitColor; mDefaultRuleSet = source.mDefaultRuleSet; mName = source.mName; mRules = source.mRules; mEnvironmentColors = source.mEnvironmentColors; defaultTextColor = source.defaultTextColor; }
public DefaultHighlightingStrategy(string name) { this.mName = name; mDigitColor = new HighlightColor(SystemColors.WindowText, false, false); defaultTextColor = new HighlightColor(SystemColors.WindowText, false, false); // set small 'default color environment' mEnvironmentColors["Default"] = new HighlightBackground("WindowText", "Window", false, false); mEnvironmentColors["Selection"] = new HighlightColor("HighlightText", "Highlight", false, false); mEnvironmentColors["VRuler"] = new HighlightColor("ControlLight", "Window", false, false); mEnvironmentColors["InvalidLines"] = new HighlightColor(Color.Red, false, false); mEnvironmentColors["CaretMarker"] = new HighlightColor(Color.Yellow, false, false); mEnvironmentColors["LineNumbers"] = new HighlightBackground("ControlDark", "Window", false, false); mEnvironmentColors["FoldLine"] = new HighlightColor(Color.FromArgb(0x80, 0x80, 0x80), Color.Black, false, false); mEnvironmentColors["FoldMarker"] = new HighlightColor(Color.FromArgb(0x80, 0x80, 0x80), Color.White, false, false); mEnvironmentColors["SelectedFoldLine"] = new HighlightColor(Color.Black, false, false); mEnvironmentColors["EOLMarkers"] = new HighlightColor("ControlLight", "Window", false, false); mEnvironmentColors["SpaceMarkers"] = new HighlightColor("ControlLight", "Window", false, false); mEnvironmentColors["TabMarkers"] = new HighlightColor("ControlLight", "Window", false, false); }
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) { PrevMarker prev = new PrevMarker(el2); prevMarkers[prev.What] = prev; } nodes = el.GetElementsByTagName("MarkFollowing"); foreach (XmlElement el2 in nodes) { NextMarker next = new NextMarker(el2); nextMarkers[next.What] = next; } }
public Span(XmlElement span) { color = new HighlightColor(span); if (span.HasAttribute("rule")) { rule = span.GetAttribute("rule"); } if (span.HasAttribute("escapecharacter")) { escapeCharacter = span.GetAttribute("escapecharacter")[0]; } name = span.GetAttribute("name"); if (span.HasAttribute("stopateol")) { stopEOL = Boolean.Parse(span.GetAttribute("stopateol")); } begin = span["Begin"].InnerText.ToCharArray(); beginColor = new HighlightColor(span["Begin"], color); if (span["Begin"].HasAttribute("singleword")) { this.isBeginSingleWord = Boolean.Parse(span["Begin"].GetAttribute("singleword")); } if (span["Begin"].HasAttribute("startofline")) { this.isBeginStartOfLine = Boolean.Parse(span["Begin"].GetAttribute("startofline")); } if (span["End"] != null) { end = span["End"].InnerText.ToCharArray(); endColor = new HighlightColor(span["End"], color); if (span["End"].HasAttribute("singleword")) { this.isEndSingleWord = Boolean.Parse(span["End"].GetAttribute("singleword")); } } }
/// <summary> /// pushes the curWord string on the word list, with the /// correct color. /// </summary> void PushCurWord(IDocument 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 (!((TextWord)words[pInd]).IsWhiteSpace) { prevWord = (TextWord)words[pInd]; if (prevWord.HasDefaultColor) { PrevMarker marker = (PrevMarker)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 = this.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, this.DefaultTextColor, true)); } else { words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false)); } } if (activeRuleSet != null) { NextMarker nextMarker = (NextMarker)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 void SetColorFor(string name, HighlightColor color) { if (name == "Default") defaultTextColor = new HighlightColor(color.Color, color.Bold, color.Italic); mEnvironmentColors[name] = color; }
// TAB public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor) { Debug.Assert(document != null); Debug.Assert(line != null); Debug.Assert(color != null); this.document = document; this.line = line; this.offset = offset; this.length = length; this.color = color; this.hasDefaultColor = hasDefaultColor; }
public TabTextWord(HighlightColor color) { length = 1; base.SyntaxColor = color; }
public TabTextWord(HighlightColor color) { length = 1; base.SyntaxColor = color; }
// TAB public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor) { Debug.Assert(document != null); Debug.Assert(line != null); Debug.Assert(color != null); this.document = document; this.line = line; this.offset = offset; this.length = length; this.color = color; this.hasDefaultColor = hasDefaultColor; }
/// <summary> /// pushes the curWord string on the word list, with the /// correct color. /// </summary> void PushCurWord(IDocument 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 (!((TextWord)words[pInd]).IsWhiteSpace) { prevWord = (TextWord)words[pInd]; if (prevWord.HasDefaultColor) { PrevMarker marker = (PrevMarker)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 = this.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, this.DefaultTextColor, true)); } else { words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false)); } } if (activeRuleSet != null) { NextMarker nextMarker = (NextMarker)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; } }
List <TextWord> ParseLine(IDocument document) { List <TextWord> words = new List <TextWord>(); HighlightColor markNext = null; currentOffset = 0; currentLength = 0; UpdateSpanStateVariables(); int currentLineLength = currentLine.Length; int currentLineOffset = currentLine.Offset; for (int i = 0; i < currentLineLength; ++i) { char ch = document.GetCharAt(currentLineOffset + i); switch (ch) { case '\n': case '\r': PushCurWord(document, ref markNext, words); ++currentOffset; break; case ' ': PushCurWord(document, ref markNext, words); if (activeSpan != null && activeSpan.Color.HasBackground) { words.Add(new TextWord.SpaceTextWord(activeSpan.Color)); } else { words.Add(TextWord.Space); } ++currentOffset; break; case '\t': PushCurWord(document, ref markNext, words); if (activeSpan != null && activeSpan.Color.HasBackground) { words.Add(new TextWord.TabTextWord(activeSpan.Color)); } else { words.Add(TextWord.Tab); } ++currentOffset; break; default: { // handle escape characters char escapeCharacter = '\0'; if (activeSpan != null && activeSpan.EscapeCharacter != '\0') { escapeCharacter = activeSpan.EscapeCharacter; } else if (activeRuleSet != null) { escapeCharacter = activeRuleSet.EscapeCharacter; } if (escapeCharacter != '\0' && escapeCharacter == ch) { // we found the escape character if (activeSpan != null && activeSpan.End != null && activeSpan.End.Length == 1 && escapeCharacter == activeSpan.End[0]) { // the escape character is a end-doubling escape character // it may count as escape only when the next character is the escape, too if (i + 1 < currentLineLength) { if (document.GetCharAt(currentLineOffset + i + 1) == escapeCharacter) { currentLength += 2; PushCurWord(document, ref markNext, words); ++i; continue; } } } else { // this is a normal \-style escape ++currentLength; if (i + 1 < currentLineLength) { ++currentLength; } PushCurWord(document, ref markNext, words); ++i; continue; } } // highlight digits if (!inSpan && (Char.IsDigit(ch) || (ch == '.' && i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1)))) && currentLength == 0) { bool ishex = false; bool isfloatingpoint = false; if (ch == '0' && i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'X') // hex digits { const string hex = "0123456789ABCDEF"; ++currentLength; ++i; // skip 'x' ++currentLength; ishex = true; while (i + 1 < currentLineLength && hex.IndexOf(Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1))) != -1) { ++i; ++currentLength; } } else { ++currentLength; while (i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1))) { ++i; ++currentLength; } } if (!ishex && i + 1 < currentLineLength && document.GetCharAt(currentLineOffset + i + 1) == '.') { isfloatingpoint = true; ++i; ++currentLength; while (i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1))) { ++i; ++currentLength; } } if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'E') { isfloatingpoint = true; ++i; ++currentLength; if (i + 1 < currentLineLength && (document.GetCharAt(currentLineOffset + i + 1) == '+' || document.GetCharAt(currentLine.Offset + i + 1) == '-')) { ++i; ++currentLength; } while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1))) { ++i; ++currentLength; } } if (i + 1 < currentLine.Length) { char nextch = Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)); if (nextch == 'F' || nextch == 'M' || nextch == 'D') { isfloatingpoint = true; ++i; ++currentLength; } } if (!isfloatingpoint) { bool isunsigned = false; if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'U') { ++i; ++currentLength; isunsigned = true; } if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'L') { ++i; ++currentLength; if (!isunsigned && i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'U') { ++i; ++currentLength; } } } words.Add(new TextWord(document, currentLine, currentOffset, currentLength, DigitColor, false)); currentOffset += currentLength; currentLength = 0; continue; } // Check for SPAN ENDs if (inSpan) { if (activeSpan.End != null && activeSpan.End.Length > 0) { if (MatchExpr(currentLine, activeSpan.End, i, document, activeSpan.IgnoreCase)) { PushCurWord(document, ref markNext, words); string regex = GetRegString(currentLine, activeSpan.End, i, document); currentLength += regex.Length; words.Add(new TextWord(document, currentLine, currentOffset, currentLength, activeSpan.EndColor, false)); currentOffset += currentLength; currentLength = 0; i += regex.Length - 1; currentSpanStack.Pop(); UpdateSpanStateVariables(); continue; } } } // check for SPAN BEGIN if (activeRuleSet != null) { foreach (Span span in activeRuleSet.Spans) { if ((!span.IsBeginSingleWord || currentLength == 0) && (!span.IsBeginStartOfLine.HasValue || span.IsBeginStartOfLine.Value == (currentLength == 0 && words.TrueForAll(delegate(TextWord textWord) { return(textWord.Type != TextWordType.Word); }))) && MatchExpr(currentLine, span.Begin, i, document, activeRuleSet.IgnoreCase)) { PushCurWord(document, ref markNext, words); string regex = GetRegString(currentLine, span.Begin, i, document); if (!OverrideSpan(regex, document, words, span, ref i)) { currentLength += regex.Length; words.Add(new TextWord(document, currentLine, currentOffset, currentLength, span.BeginColor, false)); currentOffset += currentLength; currentLength = 0; i += regex.Length - 1; if (currentSpanStack == null) { currentSpanStack = new SpanStack(); } currentSpanStack.Push(span); span.IgnoreCase = activeRuleSet.IgnoreCase; UpdateSpanStateVariables(); } goto skip; } } } // check if the char is a delimiter if (activeRuleSet != null && (int)ch < 256 && activeRuleSet.Delimiters[(int)ch]) { PushCurWord(document, ref markNext, words); if (currentOffset + currentLength + 1 < currentLine.Length) { ++currentLength; PushCurWord(document, ref markNext, words); goto skip; } } ++currentLength; skip: continue; } } } PushCurWord(document, ref markNext, words); OnParsedLine(document, currentLine, words); return(words); }
/// <summary> /// Creates a new instance of <see cref="HighlightColor"/> /// </summary> public HighlightColor(XmlElement el, HighlightColor defaultColor) { Debug.Assert(el != null, "GodLesZ.eAthenaEditor.Library.Document.SyntaxColor(XmlElement el) : el == null"); if (el.Attributes["bold"] != null) { bold = Boolean.Parse(el.Attributes["bold"].InnerText); } else { bold = defaultColor.Bold; } if (el.Attributes["italic"] != null) { italic = Boolean.Parse(el.Attributes["italic"].InnerText); } else { italic = defaultColor.Italic; } if (el.Attributes["color"] != null) { string c = el.Attributes["color"].InnerText; if (c[0] == '#') { color = ParseColor(c); } else if (c.StartsWith("SystemColors.")) { systemColor = true; systemColorName = c.Substring("SystemColors.".Length); } else { color = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]); } hasForeground = true; } else { color = defaultColor.color; } if (el.Attributes["bgcolor"] != null) { string c = el.Attributes["bgcolor"].InnerText; if (c[0] == '#') { backgroundcolor = ParseColor(c); } else if (c.StartsWith("SystemColors.")) { systemBgColor = true; systemBgColorName = c.Substring("SystemColors.".Length); } else { backgroundcolor = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]); } hasBackground = true; } else { backgroundcolor = defaultColor.BackgroundColor; } }