[svn] r5803: nemerle/trunk/ncc: completion/CodeCompletionEngine.n parsing/Lexer.n parsing/MainParser.n tes...

nazgul svnadmin at nemerle.org
Wed Oct 5 20:13:56 CEST 2005


Log:
Move completion stuff to separate subtype of LexerString

Author: nazgul
Date: Wed Oct  5 20:13:32 2005
New Revision: 5803

Modified:
   nemerle/trunk/ncc/completion/CodeCompletionEngine.n
   nemerle/trunk/ncc/parsing/Lexer.n
   nemerle/trunk/ncc/parsing/MainParser.n
   nemerle/trunk/ncc/testsuite/completion-playground/compl.n

Modified: nemerle/trunk/ncc/completion/CodeCompletionEngine.n
==============================================================================
--- nemerle/trunk/ncc/completion/CodeCompletionEngine.n	(original)
+++ nemerle/trunk/ncc/completion/CodeCompletionEngine.n	Wed Oct  5 20:13:32 2005
@@ -432,8 +432,9 @@
             
             System.Console.WriteLine (my_body);
             
+            def lexer = LexerCompletion (my_body + " ", my_body.Length);
             observed_method.GetHeader ().body =
-                FunBody.Parsed (MainParser.ParseExpr (env, my_body + " ", my_body.Length));
+                FunBody.Parsed (MainParser.ParseExpr (env, lexer));
             
             try
             {

Modified: nemerle/trunk/ncc/parsing/Lexer.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Lexer.n	(original)
+++ nemerle/trunk/ncc/parsing/Lexer.n	Wed Oct  5 20:13:32 2005
@@ -205,8 +205,6 @@
   protected mutable line : int;
   protected mutable col : int;
   protected mutable file_idx : int;
-  protected mutable currentCharNo : int;
-  protected mutable pendingToken : Token;
   
   protected static opchars : array [bool];  
   public static BaseKeywords : Set [string];
@@ -215,9 +213,6 @@
 
   protected id_buffer : StringBuilder = StringBuilder ();
 
-  // used by completion engine to mark cursor position
-  public mutable CompletionMarkAt : int;
-
 
   #region PREPROCESSOR VARIABLES
   /** if there was only white chars from beginnig of line */
@@ -246,14 +241,12 @@
     public this (name : string) { this.name = name; }
   }
 
-  public this ()
+  protected this ()
   {
     line = 1;
     col = 1;
     putback = false;
     isPendingChar = false;
-    currentCharNo = 0;
-    CompletionMarkAt = -1;
 
     white_beginning = true;
     defines = Hashtable (25);
@@ -287,10 +280,7 @@
         Message.Warning (10002, this.Location, "tab character found in input stream")
           
       | _ => ++col;
-    }
-
-    ++currentCharNo;
-
+    };
     ch
   }
 
@@ -939,37 +929,15 @@
 
   public virtual GetToken () : Token
   {
-    if (pendingToken != null) {
-      def tok = pendingToken;
-      pendingToken = null;
-      tok
-    } else {
       unless (isPendingChar)
         _ = eat_whitespace ();
       
       def last_line = line;
       def last_col = col;
       def tok = do_get_token ();
-      
-      def tok =
-        if (CompletionMarkAt == currentCharNo)
-          match (tok) {
-            | Token.Identifier (name) =>
-              CompletionMarkAt = -1;
-              Token.IdentifierToComplete (name)
-            | Token.Operator (".") =>
-              CompletionMarkAt = -1;
-              pendingToken = Token.IdentifierToComplete ("");
-              tok
-            | _ => tok
-          }
-        else
-          tok;
-
       tok.Location = Location (file_idx, last_line, last_col, line, col);
       tok
     }
-  }
 
   public Location : Location
   {
@@ -1441,7 +1409,7 @@
 public class LexerString : LexerBase
 {
   reader : string;
-  mutable pos : int;
+  protected mutable pos : int;
 
   public this (fn : string, loc : Location)
   {
@@ -1502,6 +1470,41 @@
   }
 } // LexerString
 
+public class LexerCompletion : LexerString {
+  protected mutable pendingToken : Token;
+  protected mutable CompletionMarkAt : int;
+
+  public this (fl : string, mark : int) {
+    base (fl, Location_stack.top());
+    CompletionMarkAt = mark + 1;
+  }
+
+  public override GetToken () : Token {
+    if (pendingToken != null) {
+      def tok = pendingToken;
+      pendingToken = null;
+      tok
+    }
+    else {
+      def tok = base.GetToken ();
+
+      if (CompletionMarkAt == pos)
+        match (tok) {
+          | Token.Identifier (name) =>
+            CompletionMarkAt = -1;
+            Token.IdentifierToComplete (name)
+          | Token.Operator (".") =>
+            CompletionMarkAt = -1;
+            pendingToken = Token.IdentifierToComplete ("");
+            tok
+          | _ => tok
+        }
+      else
+        tok;
+    }
+  }
+}
+
 public enum SyntaxType {
   | Identifier 
   | Keyword 

Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser.n	Wed Oct  5 20:13:32 2005
@@ -111,11 +111,18 @@
     /** Parse given string as expression, given context in which this
         expression is situated.
      */
-    public static ParseExpr (env : GlobalEnv, expr : string, completion_mark_at = -1) : PExpr
+    public static ParseExpr (env : GlobalEnv, expr : string) : PExpr
     {
       // we must prevent lexer from bailing out on last token at end of input
       def lexer = LexerString (expr + " ", Location_stack.top ());
-      lexer.CompletionMarkAt = completion_mark_at;
+      ParseExpr (env, lexer)
+    }
+
+    /** Parse given string as expression, given context in which this
+        expression is situated.
+     */
+    public static ParseExpr (env : GlobalEnv, lexer : LexerBase) : PExpr
+    {
       def preparser = PreParser (lexer);
       def tokens = preparser.PreParse ();      
       def parser = MainParser (env);

Modified: nemerle/trunk/ncc/testsuite/completion-playground/compl.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/completion-playground/compl.n	(original)
+++ nemerle/trunk/ncc/testsuite/completion-playground/compl.n	Wed Oct  5 20:13:32 2005
@@ -67,8 +67,9 @@
 
 def try_completion (body) {
   def env = my_method.DeclaringType.GlobalEnv;
+  def lexer = LexerCompletion (body + " ", body.Length);
   my_method.GetHeader ().body =
-    FunBody.Parsed (MainParser.ParseExpr (env, body + " ", body.Length));
+    FunBody.Parsed (MainParser.ParseExpr (env, lexer));
 
   try {
     my_method.RunBodyTyper ()



More information about the svn mailing list