Browse Source

Default syntax highlighting strategy can be extended - patch by Robert Zaunere.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1258 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
947d735076
  1. 48
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
  2. 15
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionParser.cs
  3. 9
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingManager.cs

48
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs

@ -112,7 +112,7 @@ namespace ICSharpCode.TextEditor.Document @@ -112,7 +112,7 @@ namespace ICSharpCode.TextEditor.Document
rules.Add(aRuleSet);
}
internal void ResolveReferences()
public void ResolveReferences()
{
// Resolve references from Span definitions to RuleSets
ResolveRuleSetReferences();
@ -184,7 +184,7 @@ namespace ICSharpCode.TextEditor.Document @@ -184,7 +184,7 @@ namespace ICSharpCode.TextEditor.Document
}
}
internal void SetColorFor(string name, HighlightColor color)
public void SetColorFor(string name, HighlightColor color)
{
if (name == "Default")
defaultTextColor = new HighlightColor(color.Color, color.Bold, color.Italic);
@ -204,7 +204,7 @@ namespace ICSharpCode.TextEditor.Document @@ -204,7 +204,7 @@ namespace ICSharpCode.TextEditor.Document
return GetColor(defaultRuleSet, document, currentSegment, currentOffset, currentLength);
}
HighlightColor GetColor(HighlightRuleSet ruleSet, IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
protected virtual HighlightColor GetColor(HighlightRuleSet ruleSet, IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
{
if (ruleSet != null) {
if (ruleSet.Reference != null) {
@ -235,10 +235,10 @@ namespace ICSharpCode.TextEditor.Document @@ -235,10 +235,10 @@ namespace ICSharpCode.TextEditor.Document
}
// Line state variable
LineSegment currentLine;
protected LineSegment currentLine;
// Span stack state variable
Stack<Span> currentSpanStack;
protected Stack<Span> currentSpanStack;
public void MarkTokens(IDocument document)
{
@ -428,13 +428,13 @@ namespace ICSharpCode.TextEditor.Document @@ -428,13 +428,13 @@ namespace ICSharpCode.TextEditor.Document
}
// Span state variables
bool inSpan;
Span activeSpan;
HighlightRuleSet activeRuleSet;
protected bool inSpan;
protected Span activeSpan;
protected HighlightRuleSet activeRuleSet;
// Line scanning state variables
int currentOffset;
int currentLength;
protected int currentOffset;
protected int currentLength;
void UpdateSpanStateVariables()
{
@ -593,18 +593,21 @@ namespace ICSharpCode.TextEditor.Document @@ -593,18 +593,21 @@ namespace ICSharpCode.TextEditor.Document
if (currentLine.MatchExpr(span.Begin, i, document)) {
PushCurWord(document, ref markNext, words);
string regex = currentLine.GetRegString(span.Begin, i, document);
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 Stack<Span>();
}
currentSpanStack.Push(span);
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;
UpdateSpanStateVariables();
i += regex.Length - 1;
if (currentSpanStack == null) {
currentSpanStack = new Stack<Span>();
}
currentSpanStack.Push(span);
UpdateSpanStateVariables();
}
goto skip;
}
@ -632,6 +635,11 @@ namespace ICSharpCode.TextEditor.Document @@ -632,6 +635,11 @@ namespace ICSharpCode.TextEditor.Document
return words;
}
protected virtual bool OverrideSpan(string spanBegin, IDocument document, List<TextWord> words, Span span, ref int lineOffset)
{
return false;
}
/// <summary>
/// pushes the curWord string on the word list, with the
/// correct color.

15
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionParser.cs

@ -16,16 +16,16 @@ using System.Reflection; @@ -16,16 +16,16 @@ using System.Reflection;
namespace ICSharpCode.TextEditor.Document
{
internal class HighlightingDefinitionParser
public static class HighlightingDefinitionParser
{
private HighlightingDefinitionParser()
{
// This is a pure utility class with no instances.
}
static ArrayList errors = null;
public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlTextReader xmlTextReader)
{
return Parse(null, syntaxMode, xmlTextReader);
}
public static DefaultHighlightingStrategy Parse(DefaultHighlightingStrategy highlighter, SyntaxMode syntaxMode, XmlTextReader xmlTextReader)
{
if (syntaxMode == null)
throw new ArgumentNullException("syntaxMode");
@ -48,7 +48,8 @@ namespace ICSharpCode.TextEditor.Document @@ -48,7 +48,8 @@ namespace ICSharpCode.TextEditor.Document
XmlDocument doc = new XmlDocument();
doc.Load(validatingReader);
DefaultHighlightingStrategy highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText);
if (highlighter == null)
highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText);
if (doc.DocumentElement.Attributes["extensions"]!= null) {
highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' });

9
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingManager.cs

@ -58,6 +58,15 @@ namespace ICSharpCode.TextEditor.Document @@ -58,6 +58,15 @@ namespace ICSharpCode.TextEditor.Document
}
}
public void AddHighlightingStrategy(IHighlightingStrategy highlightingStrategy)
{
highlightingDefs[highlightingStrategy.Name] = highlightingStrategy;
foreach (string extension in highlightingStrategy.Extensions)
{
extensionsToName[extension.ToUpperInvariant()] = highlightingStrategy.Name;
}
}
public void ReloadSyntaxModes()
{
highlightingDefs.Clear();

Loading…
Cancel
Save