Author: mkrueger
Date: 2008-02-12 12:23:47 -0500 (Tue, 12 Feb 2008)
New Revision: 95531

Added:
   
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SemanticRule.cs
Modified:
   trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am
   
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.mdp
   trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
Log:
* Mono.TextEditor.mdp, Mono.TextEditor/Document.cs,
  Mono.TextEditor.Highlighting/SyntaxMode.cs,
  Mono.TextEditor.Highlighting/SemanticRule.cs,
  Mono.TextEditor.Highlighting/SyntaxModeService.cs,
  Mono.TextEditor.Highlighting/Rule.cs, Makefile.am: Worked on
  semantic highlighting.

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-12 
17:21:16 UTC (rev 95530)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-12 
17:23:47 UTC (rev 95531)
@@ -1,5 +1,14 @@
 2008-02-12  Mike Krüger <[EMAIL PROTECTED]> 
 
+       * Mono.TextEditor.mdp, Mono.TextEditor/Document.cs,
+         Mono.TextEditor.Highlighting/SyntaxMode.cs,
+         Mono.TextEditor.Highlighting/SemanticRule.cs,
+         Mono.TextEditor.Highlighting/SyntaxModeService.cs,
+         Mono.TextEditor.Highlighting/Rule.cs, Makefile.am: Worked on semantic
+         highlighting.
+
+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,

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am       
2008-02-12 17:21:16 UTC (rev 95530)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am       
2008-02-12 17:23:47 UTC (rev 95531)
@@ -18,6 +18,7 @@
        Mono.TextEditor.Highlighting/Marker.cs \
        Mono.TextEditor.Highlighting/Match.cs \
        Mono.TextEditor.Highlighting/Rule.cs \
+       Mono.TextEditor.Highlighting/SemanticRule.cs \
        Mono.TextEditor.Highlighting/Span.cs \
        Mono.TextEditor.Highlighting/Style.cs \
        Mono.TextEditor.Highlighting/SyntaxMode.cs \

Modified: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs   
    2008-02-12 17:21:16 UTC (rev 95530)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs   
    2008-02-12 17:23:47 UTC (rev 95531)
@@ -40,6 +40,10 @@
                LineSplitter splitter;
                SyntaxMode   syntaxMode = null;
                string       eol = null;
+               
+               string mimeType;
+               string fileName;
+               
                public IBuffer Buffer {
                        get {
                                return buffer;
@@ -68,7 +72,6 @@
                        }
                }
                
-               string mimeType;
                public string MimeType {
                        get {
                                return mimeType;
@@ -432,6 +435,15 @@
                                return updateRequests.AsReadOnly ();
                        }
                }
+
+               public string FileName {
+                       get {
+                               return fileName;
+                       }
+                       set {
+                               fileName = value;
+                       }
+               }
                
                public void RequestUpdate (DocumentUpdateRequest request)
                {

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 17:21:16 UTC (rev 95530)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/Rule.cs
      2008-02-12 17:23:47 UTC (rev 95531)
@@ -27,48 +27,12 @@
 
 using System;
 using System.Text;
-using System.Text.RegularExpressions;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Xml;
 
 namespace Mono.TextEditor.Highlighting
 {
-       public class SemanticRule
-       {
-               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)
-               {
-                       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
        {
                protected string name;

Added: 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SemanticRule.cs
===================================================================
--- 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SemanticRule.cs
      2008-02-12 17:21:16 UTC (rev 95530)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SemanticRule.cs
      2008-02-12 17:23:47 UTC (rev 95531)
@@ -0,0 +1,76 @@
+//
+// SemanticRule.cs
+//
+// Author:
+//   Mike Krüger <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+
+namespace Mono.TextEditor
+{
+       public abstract class SemanticRule
+       {
+               public abstract void Analyze (Document doc, LineSegment line, 
List<Chunk> chunks, int startOffset, int endOffset);
+       }
+       
+       public class HighlightUrlSemanticRule : SemanticRule
+       {
+               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 HighlightUrlSemanticRule (string syntax)
+               {
+                       this.syntax = syntax;
+               }
+               
+               public override 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));
+                       }
+               }
+               
+       }
+}

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 17:21:16 UTC (rev 95530)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxMode.cs
        2008-02-12 17:23:47 UTC (rev 95531)
@@ -277,13 +277,42 @@
                        return null;
                }
                
-               public void AddSemanticRule (string name, SemanticRule 
semanticRule)
+               void AddSemanticRule (Rule rule, SemanticRule semanticRule)
                {
-                       Rule rule = GetRule (name);
                        if (rule != null)
                                rule.SemanticRules.Add (semanticRule);
                }
                
+               public void AddSemanticRule (SemanticRule semanticRule)
+               {
+                       AddSemanticRule (this, semanticRule);
+               }
+               
+               public void AddSemanticRule (string addToRuleName, SemanticRule 
semanticRule)
+               {
+                       AddSemanticRule (GetRule (addToRuleName), semanticRule);
+               }
+               
+               void RemoveSemanticRule (Rule rule, Type type)
+               {
+                       if (rule != null) {
+                               for (int i = 0; i < rule.SemanticRules.Count; 
i++) {
+                                       if (rule.SemanticRules[i].GetType () == 
type) {
+                                               rule.SemanticRules.RemoveAt (i);
+                                               i--;
+                                       }
+                               }
+                       }
+               }
+               public void RemoveSemanticRule (Type type)
+               {
+                       RemoveSemanticRule (this, type);
+               }
+               public void RemoveSemanticRule (string removeFromRuleName, Type 
type)
+               {
+                       RemoveSemanticRule (GetRule (removeFromRuleName), type);
+               }
+               
                public override string ToString ()
                {
                        return String.Format ("[SyntaxMode: Name={0}, 
MimeType={1}]", Name, MimeType);

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 17:21:16 UTC (rev 95530)
+++ 
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
 2008-02-12 17:23:47 UTC (rev 95531)
@@ -244,9 +244,9 @@
                                }
                                reader.Close ();
                        }
-                       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"));
+                       SyntaxModeService.GetSyntaxMode 
("text/x-csharp").AddSemanticRule ("Comment", new HighlightUrlSemanticRule 
("comment"));
+                       SyntaxModeService.GetSyntaxMode 
("text/x-csharp").AddSemanticRule ("XmlDocumentation", new 
HighlightUrlSemanticRule ("comment"));
+                       SyntaxModeService.GetSyntaxMode 
("text/x-csharp").AddSemanticRule ("String", new HighlightUrlSemanticRule 
("literal"));
                }
        }
 }
\ No newline at end of file

Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.mdp
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.mdp       
2008-02-12 17:21:16 UTC (rev 95530)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.mdp       
2008-02-12 17:23:47 UTC (rev 95531)
@@ -70,6 +70,7 @@
     <File name="Mono.TextEditor.Highlighting/Marker.cs" subtype="Code" 
buildaction="Compile" />
     <File name="UbuntuStyle.xml" subtype="Code" buildaction="EmbedAsResource" 
/>
     <File name="Mono.TextEditor/TextViewMargin.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="Mono.TextEditor.Highlighting/SemanticRule.cs" subtype="Code" 
buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

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

Reply via email to