[svn] r6756: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n Nemerle.Co...

IT svnadmin at nemerle.org
Fri Oct 13 01:12:46 CEST 2006


Log:
ScanLexer (colorizer). Comments and preprocessor.

Author: IT
Date: Fri Oct 13 01:12:35 2006
New Revision: 6756

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n	Fri Oct 13 01:12:35 2006
@@ -350,16 +350,8 @@
       {
         def loc = l1.Intersect(l2);
 
-        if (loc == l1)
-        {
-          f1();
-          f2();
-        }
-        else
-        {
-          f2();
-          f1();
-        }
+        if (loc == l1) { f1(); f2(); }
+        else           { f2(); f1(); }
       }
       else
       {

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n	Fri Oct 13 01:12:35 2006
@@ -369,22 +369,6 @@
       {
         match (expression)
         {
-        | ImplicitValueTypeCtor     
-        | StaticEventRef                                        // { from : MType.Class; ev : IEvent; }
-        | ConstantObjectRef                                     // { from : MType.Class; mem : IField; }
-        | StaticPropertyRef                                     // { from : MType.Class; prop : IProperty; }
-        | StaticRef                                             // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
-        | LocalRef                                              // { decl : LocalValue; }
-        | LocalFunRef                                           // { decl : LocalValue; type_parms : list [TyVar]; }
-        | Literal                                               // { val : Nemerle.Compiler.Literal; }
-        | MethodAddress                                         // { from : TyVar; meth : IMethod; is_virt : bool; type_parms : list [TyVar]; }
-        | Base                                                  // { base_ctor : IMethod; }
-        | TypeOf                                                // { target_type : TyVar; }
-        | OpCode                                                // { name : string; }
-        | Goto                                                  // { target : int; mutable try_block : int; }
-        | DefaultValue
-        | Error
-        | This                       => ()
         | Block         (_, e)                                  // { jump_out : LocalValue; body : TExpr; }
         | Label         (_, e)                                  // { id : int; body : TExpr; }
         | TupleIndexer  (e, _, _)                               // { obj : TExpr; pos : int; len : int; } // 0-based
@@ -425,6 +409,26 @@
 
           when (susp.IsResolved)
             Go(susp.ResolutionResult);
+
+        | _ => ()
+        /*
+        | ImplicitValueTypeCtor
+        | StaticEventRef                                        // { from : MType.Class; ev : IEvent; }
+        | ConstantObjectRef                                     // { from : MType.Class; mem : IField; }
+        | StaticPropertyRef                                     // { from : MType.Class; prop : IProperty; }
+        | StaticRef                                             // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
+        | LocalRef                                              // { decl : LocalValue; }
+        | LocalFunRef                                           // { decl : LocalValue; type_parms : list [TyVar]; }
+        | Literal                                               // { val : Nemerle.Compiler.Literal; }
+        | MethodAddress                                         // { from : TyVar; meth : IMethod; is_virt : bool; type_parms : list [TyVar]; }
+        | Base                                                  // { base_ctor : IMethod; }
+        | TypeOf                                                // { target_type : TyVar; }
+        | OpCode                                                // { name : string; }
+        | Goto                                                  // { target : int; mutable try_block : int; }
+        | DefaultValue
+        | Error
+        | This                       => ()
+        */
         }
 
         _info.Pop();

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n	Fri Oct 13 01:12:35 2006
@@ -30,6 +30,7 @@
       base.eating_stack    = Stack();
       base.eating_now      = 0;
 
+      _onPreprocessor  = false;
       _tokenInfo.Token = null;
     }
 
@@ -49,64 +50,86 @@
 
     private GetWhiteSpaceToken() : Token
     {
-        mutable str = "";
-
-        def wsloop(c)
+        def wsloop()
         {
           when (pos < reader.Length)
           {
-            match (c)
+            match (peek())
             {
-            | ' ' | '\t' | '\r' | '\n' => str += c.ToString(); wsloop(read());
-            | _ => pos--; col--;
+            | ' ' | '\t' | '\r' | '\n' => _ = read(); wsloop();
+            | _ => ()
             }
           }
         }
 
-        def last_line = line;
-        def last_col  = col;
+        wsloop();
 
-        wsloop(read());
+        Token.WhiteSpace(reader.Substring(_last_col - 1, col - _last_col));
+    }
 
-        def tok = Token.WhiteSpace(str);
+    mutable _last_line      : int;
+    mutable _last_col       : int;
+    mutable _onPreprocessor : bool;
 
-        tok.Location = Location (file_idx, last_line, last_col, line, col);
+    private FindEndOfComment() : Token.Comment
+    {
+      def idx = reader.IndexOf("*/", pos);
 
-        tok
+      if (idx >= 0)
+      {
+        _tokenInfo.ScanState &= ~ScanState.Comment;
+        pos = idx + 2;
     }
-
-    public GetToken(prevState : ScanState) : ScanTokenInfo
+      else
     {
-      _tokenInfo.ScanState = prevState;
+        _tokenInfo.ScanState |=  ScanState.Comment;
+        pos = reader.Length;
+      }
 
-      def prevToken = _tokenInfo.Token;
+      col = pos + 1;
+
+      Token.Comment(reader.Substring(_last_col - 1, col - _last_col));
+    }
+
+    private GetCommentToken() : Token
+    {
+      _ = read();
 
-      (_tokenInfo.Type, _tokenInfo.Color, _tokenInfo.Triggers) =
       match (peek())
       {
-      | ' ' | '\t' | '\n' | '\r' =>
+      | '/' =>
 
-        _tokenInfo.Token = GetWhiteSpaceToken();
+        pos = reader.Length;
+        col = pos + 1;
 
-        (
-          TP.WhiteSpace,
-          C.Text,
-          if (pos+1 >= reader.Length && (_tokenInfo.Token :> Token.WhiteSpace).value == "")
-            match (prevToken)
+        Token.Comment(reader.Substring(_last_col - 1));
+
+      | '*' =>
+
+        _ = read();
+        FindEndOfComment()
+
+      | _   => pos--; col--; null
+      }
+    }
+
+    private GetPreprocessorToken() : Token
             {
-            | Keyword (name) when name == "using"
-            | Operator(name) when name == "|"     => TR.MemberSelect
-            | _                                   => TR.None
+      _ = read();
+
+      Token.Keyword("#");
             }
-          else
-            TR.None
-        )
 
-      | _ =>
+    public GetToken(prevState : ScanState) : ScanTokenInfo
+    {
+      _last_line = line;
+      _last_col  = col;
 
-        _tokenInfo.Token = base.GetToken();
+      def getBaseToken()
+      {
+        def tok = base.GetToken();
 
-        match (_tokenInfo.Token)
+        def (tp, color, trigger) = match (tok)
         {
         | Identifier(nm) when _types.ContainsKey(nm)
         | Keyword                   => (TP.Keyword,    C.Keyword,    TR.None)
@@ -133,18 +156,75 @@
         | EndSquare      /* ]  */   => (TP.Operator,   C.Operator,   TR.MatchBraces)
         | BeginQuote     /* <[ */
         | EndQuote       /* ]> */
-        | RoundGroup                   // { Child : Token; }         // ( ... )
-        | BracesGroup                  // { Child : Token; }         // { ... }
-        | SquareGroup                  // { mutable Child : Token; } // [ ... ]
-        | QuoteGroup                   // { Child : Token; }         // <[ ... ]>
-        | LooseGroup                   // { mutable Child : Token; } // ; ... ;
-        | Namespace                    // { Env : GlobalEnv; Body : Token; }
-        | Using                        // { Env : GlobalEnv; }
-        | EndOfFile
-        | EndOfGroup                => (TP.Unknown,    C.Text,       TR.None)
+        | _                         => (TP.Unknown,    C.Text,       TR.None)
+        }
+
+        (tok, tp, color, trigger)
+      }
+
+      when (reader == " 0")
+      {
+        def _s = reader.Substring(pos);
+      }
+
+      _tokenInfo.ScanState = prevState;
+
+      (_tokenInfo.Token, _tokenInfo.Type, _tokenInfo.Color, _tokenInfo.Triggers)
+        =
+      if (pos >= reader.Length)
+      {
+          (Token.EndOfFile(), TP.Unknown, C.Text, TR.None)
+      }
+      else if ((prevState & ScanState.Comment) != 0)
+      {
+          (FindEndOfComment(), TP.Comment, C.Comment, TR.None)
+      }
+      else
+      {
+        match (peek())
+        {
+        | ' ' | '\t' | '\n' | '\r' =>
+
+          def tok = GetWhiteSpaceToken();
+
+          (
+            tok,
+            TP.WhiteSpace,
+            C.Text,
+            if (pos+1 >= reader.Length && (tok :> Token.WhiteSpace).value == "")
+              match (_tokenInfo.Token)
+              {
+              | Keyword (name) when name == "using"
+              | Operator(name) when name == "|"     => TR.MemberSelect
+              | _                                   => TR.None
+              }
+            else
+              TR.None
+          )
+
+        | '#' when white_beginning =>
+
+          _onPreprocessor = true;
+          white_beginning = false;
+
+          _ = read();
+
+          (Token.Keyword("#"), TP.Keyword, C.Keyword, TR.MemberSelect)
+
+        | '/' =>
+
+          def tok = GetCommentToken();
+
+          if (tok != null)
+            (tok, TP.Comment, C.Comment, TR.None)
+          else
+            getBaseToken();
+
+        | _ => getBaseToken();
         }
       }
 
+      _tokenInfo.Token.Location = Location(file_idx, _last_line, _last_col, line, col);
       _tokenInfo
     }
   }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n	Fri Oct 13 01:12:35 2006
@@ -12,6 +12,6 @@
   | String     = 4
   | Number     = 5
 
-  | Operator
+  | Operator   = 7
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n	Fri Oct 13 01:12:35 2006
@@ -7,15 +7,15 @@
 {
   public class ScanTokenInfo
   {
-    [Accessor(flags=WantSetter)] mutable _token     : Token;
-    [Accessor(flags=WantSetter)] mutable _scanState : ScanState;
-    [Accessor(flags=WantSetter)] mutable _color     : ScanTokenColor;
-    [Accessor(flags=WantSetter)] mutable _triggers  : ScanTokenTriggers;
-    [Accessor(flags=WantSetter)] mutable _type      : ScanTokenType;
+    public mutable Token     : Token;
+    public mutable ScanState : ScanState;
+    public mutable Color     : ScanTokenColor;
+    public mutable Triggers  : ScanTokenTriggers;
+    public mutable Type      : ScanTokenType;
 
     public IsEndOfLine : bool
     {
-      get { match (_token) { | EndOfFile => true | _ => false } }
+      get { match (Token) { | EndOfFile => true | _ => false } }
     }
   }
 }

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleColorableItem.cs	Fri Oct 13 01:12:35 2006
@@ -30,20 +30,12 @@
 
 		public int GetDefaultColors(COLORINDEX[] piForeground, COLORINDEX[] piBackground)
 		{
-			if (piForeground == null)
-				throw new ArgumentNullException("piForeground");
-
-			if (piForeground.Length == 0)
-				throw new ArgumentOutOfRangeException("piForeground");
+			if (piForeground        == null) throw new ArgumentNullException("piForeground");
+			if (piBackground        == null) throw new ArgumentNullException("piBackground");
+			if (piForeground.Length == 0)    throw new ArgumentOutOfRangeException("piForeground");
+			if (piBackground.Length == 0)    throw new ArgumentOutOfRangeException("piBackground");
 
 			piForeground[0] = _foreground;
-
-			if (piBackground == null)
-				throw new ArgumentNullException("piBackground");
-
-			if (piBackground.Length == 0)
-				throw new ArgumentOutOfRangeException("piBackground");
-
 			piBackground[0] = _background;
 
 			return VSConstants.S_OK;

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs	Fri Oct 13 01:12:35 2006
@@ -61,7 +61,7 @@
 			tokenInfo.StartIndex = info.Token.Location.Column    - 1;
 			tokenInfo.EndIndex   = info.Token.Location.EndColumn - 2;
 
-			return !info.IsEndOfLine;;
+			return !info.IsEndOfLine;
 		}
 
 		public void SetSource(string source, int offset)



More information about the svn mailing list