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. 50
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
  2. 17
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionParser.cs
  3. 9
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingManager.cs

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

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

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

@ -16,16 +16,16 @@ using System.Reflection;
namespace ICSharpCode.TextEditor.Document 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; static ArrayList errors = null;
public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlTextReader xmlTextReader) 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) if (syntaxMode == null)
throw new ArgumentNullException("syntaxMode"); throw new ArgumentNullException("syntaxMode");
@ -48,7 +48,8 @@ namespace ICSharpCode.TextEditor.Document
XmlDocument doc = new XmlDocument(); XmlDocument doc = new XmlDocument();
doc.Load(validatingReader); 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) { if (doc.DocumentElement.Attributes["extensions"]!= null) {
highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' }); highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' });

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

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

Loading…
Cancel
Save