Author: fejj
Date: 2007-03-07 14:43:18 -0500 (Wed, 07 Mar 2007)
New Revision: 73902

Modified:
   trunk/monodevelop/Extras/CSharpBinding/ChangeLog
   
trunk/monodevelop/Extras/CSharpBinding/FormattingStrategy/CSharpIndentEngine.cs
Log:
2007-03-07  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        * FormattingStrategy/CSharpIndentEngine.cs (PushHash): Doh, how
        did I overlook this method when integrating my IndentEngine into
        MD?

        Fix for making "default :" (as opposed to "default:") inside a
        switch-statement work as it should, lwsp is not significant here.

        * FormattingStrategy/CSharpIndentEngine.cs (PushOpenParen): Clear
        the keyword after pushing a new ParenList onto the stack, when the
        ParenList is popped, the keyword is restored.
        (Reset): Changed the semantics of wordStart, this now initializes
        to -1 instead of 0.
        (PushNewLine): Reset wordStart back to -1.
        (Push): When checking for a keyword, we don't need to use
        lastNonLwsp anymore, just use wordStart.
        (Push): wordStart should always be set to point to the beginning
        of a word token (and never to word-delimiting chars like it was
        before).



Modified: trunk/monodevelop/Extras/CSharpBinding/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/CSharpBinding/ChangeLog    2007-03-07 19:40:32 UTC 
(rev 73901)
+++ trunk/monodevelop/Extras/CSharpBinding/ChangeLog    2007-03-07 19:43:18 UTC 
(rev 73902)
@@ -1,5 +1,26 @@
 2007-03-07  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
+       * FormattingStrategy/CSharpIndentEngine.cs (PushHash): Doh, how
+       did I overlook this method when integrating my IndentEngine into
+       MD?
+
+       Fix for making "default :" (as opposed to "default:") inside a
+       switch-statement work as it should, lwsp is not significant here.
+
+       * FormattingStrategy/CSharpIndentEngine.cs (PushOpenParen): Clear
+       the keyword after pushing a new ParenList onto the stack, when the
+       ParenList is popped, the keyword is restored.
+       (Reset): Changed the semantics of wordStart, this now initializes
+       to -1 instead of 0.
+       (PushNewLine): Reset wordStart back to -1.
+       (Push): When checking for a keyword, we don't need to use
+       lastNonLwsp anymore, just use wordStart.
+       (Push): wordStart should always be set to point to the beginning
+       of a word token (and never to word-delimiting chars like it was
+       before).
+
+2007-03-07  Jeffrey Stedfast  <[EMAIL PROTECTED]>
+
        * Gui/CSharpTextEditorExtension.cs: Fixed a bug preventing
        tab-completion from working by chaining the KeyPress() to the
        parent.

Modified: 
trunk/monodevelop/Extras/CSharpBinding/FormattingStrategy/CSharpIndentEngine.cs
===================================================================
--- 
trunk/monodevelop/Extras/CSharpBinding/FormattingStrategy/CSharpIndentEngine.cs 
    2007-03-07 19:40:32 UTC (rev 73901)
+++ 
trunk/monodevelop/Extras/CSharpBinding/FormattingStrategy/CSharpIndentEngine.cs 
    2007-03-07 19:43:18 UTC (rev 73902)
@@ -3,7 +3,6 @@
 
 using MonoDevelop.SourceEditor.Properties;
 
-
 namespace CSharpBinding.FormattingStrategy {
        public partial class CSharpIndentEngine : ICloneable {
                IndentStack stack;
@@ -124,7 +123,7 @@
                        commentEndedAt = -1;
                        firstNonLwsp = -1;
                        lastNonLwsp = -1;
-                       wordStart = 0;
+                       wordStart = -1;
                        
                        pc = '\0';
                        lc = '\0';
@@ -181,7 +180,7 @@
                        }
                }
                
-               string IsKeyword ()
+               string WordIsKeyword ()
                {
                        string str = linebuf.ToString (wordStart, 
linebuf.Length - wordStart);
                        string[] keywords = new string [] {
@@ -209,7 +208,7 @@
                        return null;
                }
                
-               bool IsDefault ()
+               bool WordIsDefault ()
                {
                        string str = linebuf.ToString (wordStart, 
linebuf.Length - wordStart).Trim ();
                        
@@ -227,6 +226,22 @@
                }
                
                // Handlers for specific characters
+               void PushHash (Inside inside)
+               {
+                       // ignore if we are inside a string, char, or comment
+                       if ((inside & (Inside.StringOrChar | Inside.Comment)) 
!= 0)
+                               return;
+                       
+                       // ignore if '#' is not the first significant char on 
the line
+                       if (lc != '\0')
+                               return;
+                       
+                       stack.Push (Inside.PreProcessor, keyword, curLineNr, 0);
+                       
+                       curIndent = String.Empty;
+                       needsReindent = true;
+               }
+               
                void PushSlash (Inside inside)
                {
                        // ignore these
@@ -341,7 +356,7 @@
                                return;
                        
                        // can't be a case/label if there's no preceeding text
-                       if (firstNonLwsp == -1)
+                       if (wordStart == -1)
                                return;
                        
                        // goto-label or case statement
@@ -424,6 +439,8 @@
                                n += linebuf.Length - firstNonLwsp;
                        
                        stack.Push (Inside.ParenList, keyword, curLineNr, n);
+                       
+                       keyword = String.Empty;
                }
                
                void PushCloseParen (Inside inside)
@@ -616,7 +633,7 @@
                        commentEndedAt = -1;
                        firstNonLwsp = -1;
                        lastNonLwsp = -1;
-                       wordStart = 0;
+                       wordStart = -1;
                        
                        pc = '\0';
                        lc = '\0';
@@ -642,20 +659,23 @@
                        
                        needsReindent = false;
                        
-                       if ((inside & (Inside.PreProcessor | 
Inside.StringOrChar | Inside.Comment)) == 0 
-                           && firstNonLwsp != -1 && linebuf.Length > 
wordStart) {
+                       if ((inside & (Inside.PreProcessor | 
Inside.StringOrChar | Inside.Comment)) == 0 &&
+                           wordStart != -1 && (linebuf.Length - wordStart) > 
1) {
                                if (Char.IsWhiteSpace (c) || c == '(' || c == 
'{') {
-                                       string tmp = IsKeyword ();
+                                       string tmp = WordIsKeyword ();
                                        if (tmp != null)
                                                keyword = tmp;
-                               } else if (c == ':' && IsDefault ()) {
+                               } else if (c == ':' && WordIsDefault ()) {
                                        keyword = "default";
                                }
                        }
                        
-                       // Console.WriteLine ("Pushing '{0}'; keyword = {1}", 
c, keyword);
+                       //Console.WriteLine ("Pushing '{0}'; wordStart = {1}; 
keyword = {2}", c, wordStart, keyword);
                        
                        switch (c) {
+                       case '#':
+                               PushHash (inside);
+                               break;
                        case '/':
                                PushSlash (inside);
                                break;
@@ -702,35 +722,38 @@
                                break;
                        }
                        
-                       pc = c;
-                       if (!Char.IsWhiteSpace (c))
-                               lc = c;
-                       
                        inside = stack.PeekInside (0);
                        if ((inside & (Inside.PreProcessor | 
Inside.StringOrChar | Inside.Comment)) == 0) {
                                if (!Char.IsWhiteSpace (c)) {
                                        if (firstNonLwsp == -1)
                                                firstNonLwsp = linebuf.Length;
                                        
-                                       if (lastNonLwsp != -1 && c != ':' && 
lastNonLwsp != linebuf.Length - 1) {
+                                       if (wordStart != -1 && c != ':' && 
Char.IsWhiteSpace (pc)) {
                                                // goto labels must be single 
word tokens
                                                canBeLabel = false;
-                                       } else if (lastNonLwsp == -1 && 
Char.IsDigit (c)) {
+                                       } else if (wordStart == -1 && 
Char.IsDigit (c)) {
                                                // labels cannot start with a 
digit
                                                canBeLabel = false;
                                        }
                                        
                                        lastNonLwsp = linebuf.Length;
                                        
-                                       if (c == ':')
-                                               wordStart = linebuf.Length + 1;
-                               } else {
-                                       wordStart = linebuf.Length + 1;
+                                       if (c != ':') {
+                                               if (Char.IsWhiteSpace (pc) || 
lc == ':')
+                                                       wordStart = 
linebuf.Length;
+                                               else if (pc == '\0')
+                                                       wordStart = 0;
+                                       }
                                }
-                       } else if (c != '\\') {
+                       } else if (c != '\\' && (inside & (Inside.StringLiteral 
| Inside.CharLiteral)) != 0) {
+                               // Note: PushBackSlash() will handle untoggling 
isEscaped if c == '\\'
                                isEscaped = false;
                        }
                        
+                       pc = c;
+                       if (!Char.IsWhiteSpace (c))
+                               lc = c;
+                       
                        linebuf.Append (c);
                        
                        cursor++;

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

Reply via email to