Author: mkrueger
Date: 2008-02-12 06:08:18 -0500 (Tue, 12 Feb 2008)
New Revision: 95489

Modified:
   trunk/monodevelop/main/src/addins/Mono.Texteditor/CSharpSyntaxMode.xml
   trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSplitter.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs
Log:
* CSharpSyntaxMode.xml, Mono.TextEditor/LineSplitter.cs,
  Mono.TextEditor/TextMarker.cs, Mono.TextEditor/TextEditor.cs,
  Mono.TextEditor/LineSegment.cs,
  Mono.TextEditor.Highlighting/SyntaxMode.cs,
  Mono.TextEditor.Highlighting/SyntaxModeService.cs,
  Mono.TextEditor.Highlighting/Rule.cs: Started support for semantic
  highlighting. Urls+email addresses in comments and strings are
  highlighted.

  (Yes I know that THIS doesn't need to be done with semantic
  highlighting, but I need to test it out somewhere)

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/CSharpSyntaxMode.xml
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/CSharpSyntaxMode.xml      
2008-02-12 10:14:14 UTC (rev 95488)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/CSharpSyntaxMode.xml      
2008-02-12 11:08:18 UTC (rev 95489)
@@ -34,12 +34,12 @@
                <End>*/</End>
        </Span>
        
-       <Span color = "literal" stopateol = "false" escape='"'>
+       <Span color = "literal" rule="String" stopateol = "false" escape='"'>
                <Begin>@"</Begin>
                <End>"</End>
        </Span>
 
-       <Span color = "literal" stopateol = "true" escape="\">
+       <Span color = "literal" rule="String" stopateol = "true" escape="\">
                <Begin>"</Begin>
                <End>"</End>
        </Span>
@@ -218,6 +218,9 @@
                </Keywords>     
        </Rule>
        
+       <Rule name = "String">
+       </Rule>
+       
        <Rule name = "XmlDocumentation">
                <Span color = "literal" stopateol = "true" escape="\">
                        <Begin>"</Begin>

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-12 
10:14:14 UTC (rev 95488)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-12 
11:08:18 UTC (rev 95489)
@@ -1,5 +1,19 @@
 2008-02-12  Mike Krüger <[EMAIL PROTECTED]> 
 
+       * CSharpSyntaxMode.xml, Mono.TextEditor/LineSplitter.cs,
+         Mono.TextEditor/TextMarker.cs, Mono.TextEditor/TextEditor.cs,
+         Mono.TextEditor/LineSegment.cs,
+         Mono.TextEditor.Highlighting/SyntaxMode.cs,
+         Mono.TextEditor.Highlighting/SyntaxModeService.cs,
+         Mono.TextEditor.Highlighting/Rule.cs: Started support for semantic
+         highlighting. Urls+email addresses in comments and strings are
+         highlighted.
+       
+         (Yes I know that THIS doesn't need to be done with semantic
+         highlighting, but I need to test it out somewhere)
+
+2008-02-12  Mike Krüger <[EMAIL PROTECTED]> 
+
        * Mono.TextEditor/TextViewMargin.cs, Mono.TextEditor/Document.cs,
          Mono.TextEditor/FoldMarkerMargin.cs, 
Mono.TextEditor/BookmarkMargin.cs,
          Mono.TextEditor/GutterMargin.cs,

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
    2008-02-12 10:14:14 UTC (rev 95488)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSegment.cs
    2008-02-12 11:08:18 UTC (rev 95489)
@@ -123,14 +123,38 @@
                        markers.Add (marker);
                }
                
+               public void ClearMarker ()
+               {
+                       if (markers != null) {
+                               markers.Clear ();
+                               markers = null;
+                       }
+               }
+               
                public void RemoveMarker (TextMarker marker)
                {
                        marker.LineSegment = null;
+                       if (markers == null)
+                               return;
                        markers.Remove (marker);
                        if (markers.Count == 0)
                                markers = null;
                }
                
+               public void RemoveMarker (Type type)
+               {
+                       if (markers == null)
+                               return;
+                       for (int i = 0; i < markers.Count; i++) {
+                               if (markers[i].GetType () == type) {
+                                       RemoveMarker (markers[i]);
+                                       if (markers == null)
+                                               return;
+                                       i--;
+                               }
+                       }
+               }
+               
                public override string ToString ()
                {
                        return String.Format ("[LineSegment: Offset={0}, 
Length={1}, DelimiterLength={2}, StartSpan={3}]", this.Offset, this.Length, 
this.DelimiterLength, StartSpan == null ? "null" : StartSpan.Length.ToString());

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSplitter.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSplitter.cs
   2008-02-12 10:14:14 UTC (rev 95488)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/LineSplitter.cs
   2008-02-12 11:08:18 UTC (rev 95489)
@@ -140,6 +140,7 @@
                                int newLineLength = line.EndOffset - (offset + 
textOffset);
                                int oldDelimiterLength = line.DelimiterLength;
                                lines.ChangeLength (line, offset + 
delimiter.EndOffset - line.Offset, delimiter.Length);
+                               line.ClearMarker ();
                                line = this.lines.InsertAfter (line, 
newLineLength, oldDelimiterLength);
 //                             OnLineLenghtChanged (new LineEventArgs (line));
                                textOffset = delimiter.EndOffset;

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-02-12 10:14:14 UTC (rev 95488)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs 
    2008-02-12 11:08:18 UTC (rev 95489)
@@ -549,7 +549,6 @@
                                return this.textViewMargin.LineHeight;
                        }
                }
-
                
                public Gdk.Point DocumentToVisualLocation (DocumentLocation loc)
                {
@@ -600,6 +599,10 @@
                                                       this.Allocation.Width,
                                                       this.Allocation.Width);
                }
+               public int GetWidth (string text)
+               {
+                       return this.textViewMargin.GetWidth (text);
+               }
                
                protected override bool OnExposeEvent (Gdk.EventExpose e)
                {

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs 
    2008-02-12 10:14:14 UTC (rev 95488)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextMarker.cs 
    2008-02-12 11:08:18 UTC (rev 95489)
@@ -28,6 +28,38 @@
 
 namespace Mono.TextEditor
 {
+       public class UrlMarker : TextMarker
+       {
+               string url;
+               string style;
+               int startColumn;
+               int endColumn;
+               LineSegment line;
+               
+               public UrlMarker (LineSegment line, string url, string style, 
int startColumn, int endColumn)
+               {
+                       this.line        = line;
+                       this.url         = url;
+                       this.style       = style;
+                       this.startColumn = startColumn;
+                       this.endColumn   = endColumn;
+               }
+               
+               public override void Draw (TextEditor editor, Gdk.Window win, 
int startOffset, int endOffset, int y, int startXPos, int endXPos)
+               {
+                       using (Gdk.GC gc = new Gdk.GC (win)) {
+                               int width1 = editor.GetWidth 
(editor.Buffer.GetTextAt (line.Offset, startColumn));
+                               int width2 = editor.GetWidth 
(editor.Buffer.GetTextAt (line.Offset + startColumn, endColumn - startColumn));
+                               gc.RgbFgColor = editor.ColorStyle.GetChunkStyle 
(style).Color;
+                               win.DrawLine (gc, 
+                                             startXPos + width1,
+                                             y + editor.LineHeight - 1,
+                                             startXPos + width1 + width2,
+                                             y + editor.LineHeight - 1);
+                       }
+               }
+       }
+       
        public class TextMarker
        {
                LineSegment lineSegment;
@@ -41,7 +73,7 @@
                        }
                }
                
-               public void Draw (TextEditor editor, Gdk.Window win, int 
startOffset, int endOffset, int y, int startXPos, int endXPos)
+               public virtual void Draw (TextEditor editor, Gdk.Window win, 
int startOffset, int endOffset, int y, int startXPos, int endXPos)
                {
                        using (Gdk.GC gc = new Gdk.GC (win)) {
                                gc.RgbFgColor = new Color (255, 0, 0);

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
      2008-02-12 10:14:14 UTC (rev 95488)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
      2008-02-12 11:08:18 UTC (rev 95489)
@@ -27,6 +27,7 @@
 
 using System;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Xml;
@@ -35,10 +36,38 @@
 {
        public class SemanticRule
        {
-               public virtual void Analyze (Document doc, List<Chunk> chunks, 
int startOffset, int endOffset)
+               const string urlRegexStr = "https?://"
+                               + "?(([0-9a-z_!~*'().&=+$%-]+: 
)?[0-9a-z_!~*'().&=+$%-]+@)?" //user@
+                               + @"(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP- 
199.194.52.184
+                               + "|" // allows either IP or domain
+                               + @"([0-9a-z_!~*'()-]+\.)*" // tertiary 
domain(s)- www.
+                               + @"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 
second level domain
+                               + "[a-z]{2,6})" // first level domain- .com or 
.museum
+                               + "(:[0-9]{1,4})?" // port number- :80
+                               + "((/?)|" // a slash isn't required if there 
is no file name
+                               + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)"; 
+               
+               static Regex urlRegex = new Regex (urlRegexStr, 
RegexOptions.Compiled);
+               static Regex mailRegex = new Regex (@"[EMAIL PROTECTED],4}", 
RegexOptions.Compiled);
+               string syntax;
+               
+               public SemanticRule (string syntax)
                {
-//                     System.Console.WriteLine(doc.Buffer.GetTextAt 
(startOffset, endOffset - startOffset));
+                       this.syntax = syntax;
                }
+               
+               public virtual void Analyze (Document doc, LineSegment line, 
List<Chunk> chunks, int startOffset, int endOffset)
+               {
+                       string text = doc.Buffer.GetTextAt (startOffset, 
endOffset - startOffset);
+                       int startColumn = startOffset - line.Offset;
+                       line.RemoveMarker (typeof(UrlMarker));
+                       foreach (System.Text.RegularExpressions.Match m in 
urlRegex.Matches (text)) {
+                               line.AddMarker (new UrlMarker (line, m.Value, 
syntax, startColumn + m.Index, startColumn + m.Index + m.Length));
+                       }
+                       foreach (System.Text.RegularExpressions.Match m in 
mailRegex.Matches (text)) {
+                               line.AddMarker (new UrlMarker (line, m.Value, 
syntax, startColumn + m.Index, startColumn + m.Index + m.Length));
+                       }
+               }
        }
        public class Rule
        {

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
        2008-02-12 10:14:14 UTC (rev 95488)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
        2008-02-12 11:08:18 UTC (rev 95489)
@@ -139,6 +139,11 @@
                        void SetSpan (int offset)
                        {
                                curSpan = spanStack.Count > 0 ? spanStack.Peek 
() : null;
+                               if (curRule != null) {
+                                       foreach (SemanticRule semanticRule in 
curRule.SemanticRules) {
+                                               semanticRule.Analyze (this.doc, 
line, result, ruleStart, offset);
+                                       }
+                               }
                                if (curSpan != null) { 
                                        curRule = mode.GetRule (curSpan.Rule);
                                        if (curRule == null) {
@@ -151,11 +156,7 @@
                                        curRule  = mode;
                                        spanTree = curRule.spanTree;
                                }
-                               if (curRule != null) {
-                                       foreach (SemanticRule semanticRule in 
curRule.SemanticRules) {
-                                               semanticRule.Analyze (this.doc, 
result, ruleStart, offset);
-                                       }
-                               }
+                               
                                ruleStart = offset;
                        }
                        

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
 2008-02-12 10:14:14 UTC (rev 95488)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
 2008-02-12 11:08:18 UTC (rev 95489)
@@ -244,7 +244,9 @@
                                }
                                reader.Close ();
                        }
-                       SyntaxModeService.GetSyntaxMode 
("text/x-csharp").AddSemanticRule ("Comment", new SemanticRule ());
+                       SyntaxModeService.GetSyntaxMode 
("text/x-csharp").AddSemanticRule ("Comment", new SemanticRule ("comment"));
+                       SyntaxModeService.GetSyntaxMode 
("text/x-csharp").AddSemanticRule ("XmlDocumentation", new SemanticRule 
("comment"));
+                       SyntaxModeService.GetSyntaxMode 
("text/x-csharp").AddSemanticRule ("String", new SemanticRule ("literal"));
                }
        }
 }
\ No newline at end of file

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to