[svn] r6806: vs-plugin/trunk/Nemerle.Compiler.Utils: Nemerle.Compiler.Utils.csproj Nemerle.Completion2/Cod...

IT svnadmin at nemerle.org
Sun Oct 29 06:15:16 CET 2006


Log:
Rewrote ExprFinder.

Author: IT
Date: Sun Oct 29 06:15:12 2006
New Revision: 6806

Added:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/TokenFinder.n
Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	Sun Oct 29 06:15:12 2006
@@ -146,6 +146,9 @@
   <ItemGroup>
     <Compile Include="Nemerle.Completion2\CodeModel\ScanTokenType.n" />
   </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Nemerle.Completion2\CodeModel\TokenFinder.n" />
+  </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

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	Sun Oct 29 06:15:12 2006
@@ -16,325 +16,196 @@
   {
     mutable _line          : int;
     mutable _col           : int;
-    mutable _counter       : int;
-    mutable _curLocation   : Location;
-    mutable _retObject     : object;
-    mutable _retLocation   : Location;
+    mutable _pexprObject   : object;
+    mutable _texprObject   : object;
     mutable _pexprLocation : Location;
-    mutable _findLocation  : bool;
+    mutable _texprLocation : Location;
+    mutable _stop          : bool;
 
-    mutable __stop          : bool;
+    PExprName : string
+    {
+      get { if (_pexprObject == null) null else _pexprObject.ToString() }
+    }
 
-    _stop : bool
+    IgnorePExpr(obj : object) : bool
     {
-      get { __stop }
-      set
+      match (obj)
       {
-        __stop = value
+      | PExpr.Sequence
+      | PExpr.Is       => true
+      | _              => false
       }
     }
 
-    #region Find PExpr
-
     PFinder(info : ExprWalkInfo) : void
     {
-      when (info.Node is PExpr.Literal || !IsIn(_curLocation))
-        return;
-
       when (info.Node is Located)
-        Print(info.Node :> Located, info.Nodes.Length);
+      {
+        def loc = (info.Node :> Located).Location;
 
-      match (info.Node)
+        when (IsIn(loc))
       {
-      | pexpr is PExpr =>
+          Print(info.Node, loc, info.Nodes.Length);
 
-        match (pexpr)
+          when (!IgnorePExpr(info.Node))
         {
-        | Wildcard
-        | MacroCall              => CheckLocated(pexpr);
-        | ToComplete(o : object)
-        | TypedType (o : object)
-        | Ref       (o : object) => CheckObject(pexpr.Location, o);
-        | _ => ()
-        }
+            when (_pexprObject == null || _pexprLocation.Intersect(loc) == loc)
+            {
+              PrintAdd(info.Nodes.Length);
 
-      | sp is Splicable =>
+              _pexprLocation = loc;
+              _pexprObject   = info.Node;
+            }
 
-        match (sp)
+            match (info.Node)
         {
-        | HalfId(name) => CheckObject (sp.Location, name)
-        | Name         => CheckLocated(sp)
+            | PExpr.Wildcard
+            | PExpr.MacroCall => info.Stop();
         | _ => ()
         }
-      | _ => ()
       }
-
-      when (_stop)
-        info.Stop();
     }
-
-    public Find(root : PExpr, line : int, col : int) : Location * object
-    {
-      Init(root.Location, line, col);
-
-      ExprWalker().Walk(root, PFinder);
-
-      (_retLocation, _retObject)
+      }
     }
 
-    #endregion 
-
-    #region Find TExpr
-
-    FindPattern(pattern : Pattern, info : ExprWalkInfo) : void
+    GetPattern(pattern : Pattern) : object
     {
-      match (pattern)
-      {
-      | Error                  =>
-
-        _stop = _stop || IsIn(pattern.Location);
-
-      | Application(name, arg) =>
-
-        info.Walk(arg);
-        CheckObject(pattern.Location, name);
-
-      | HasType    (typ)       =>
-
-        CheckObject(pattern.Location, typ);
+    | Application(name, _)    =>   // { name : TypeInfo; arg : Pattern; }
 
-      | As(Wildcard, decl) when decl.Location.Line < pattern.Location.Line =>
+      def dt = name.DeclaringType;
+      if (dt != null && dt.Name == PExprName) dt else name
 
-        CheckObject(pattern.Location, decl)
-
-      | As(pattern, decl) =>
-
-        Check(
-          pattern.Location, () => info.Walk(pattern),
-          decl.   Location, () => CheckLocated(decl));
-
-      | _ => ()
-      }
+    | HasType    (o : object)      // { typ : MType; }
+    | As      (_, o : object) => o // { pat : Pattern; decl : LocalValue; }
+    | _                       => pattern
     }
 
-    FindExpr(expression : TExpr, info : ExprWalkInfo) : void
-    {
-      when (_findLocation && _pexprLocation.IsEqualExcludingFile(expression.Location))
+    GetExpr(expression : TExpr) : object
       {
-        _retObject   = expression;
-        _retLocation = _pexprLocation;
+    | StaticRef(from, mem, _)          =>      // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
 
-        info.Stop();
-        return;
-      }
+      if (from.tycon.Name == PExprName) from else mem : object
 
-      match (expression)
-      {
-      | StaticRef        (_, o : object, _)      // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
       | ConstantObjectRef(_, o : object)         // { from : MType.Class; mem : IField; }
       | StaticPropertyRef(_, o : object)         // { from : MType.Class; prop : IProperty; }
       | StaticEventRef   (_, o : object)         // { from : MType.Class; ev : IEvent; }
-      | Base                (o : object) =>      // { base_ctor : IMethod; }
-
-        CheckObject(expression.Location, o);
-
-      | LocalFunRef         (decl, _)            // { decl : LocalValue; type_parms : list [TyVar]; }
-      | LocalRef            (decl)       =>      // { decl : LocalValue; }
-
-        unless (decl.ExpandedBlockReturn)
-          CheckObject(expression.Location, decl);
-
-      | Error
-      | ImplicitValueTypeCtor
-      //| DefaultValue
-      | Goto                                     // { target : int; mutable try_block : int; }
-      | This
-      | OpCode                             =>    // { name : string; }
-
-        _stop = _stop || IsIn(expression.Location);
-
-      | MethodRef     (obj, mem : IMember, _, _) // { obj : TExpr; meth : IMethod; type_parms : list [TyVar]; notvirtual : bool; }
-      | EventMember   (obj, mem : IMember)       // { obj : TExpr; ev : IEvent; }
-      | FieldMember   (obj, mem : IMember)       // { obj : TExpr; fld : IField; }
-      | PropertyMember(obj, mem : IMember) =>    // { obj : TExpr; prop : IProperty; }
-
-        Check(
-          expression.Location, () => CheckObject(expression.Location, mem),
-          obj.Location,        () => info.Walk(obj));
-
-      | TypeConversion(e, t, _)            =>    // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
-
-        info.Walk(e);
-        CheckObject(expression.Location, t);
-
-      | DefValIn(nm, val, body)            =>    // { name : LocalValue; val : TExpr; mutable body : TExpr; }
-
-        Check(
-          nm. Location, () => unless (nm.ExpandedBlockReturn) CheckLocated(nm),
-          val.Location, () => info.Walk(val));
-
-        unless (body == null)
-          info.Walk(body);
-
-      | Sequence(Call(Base as b, _, _), e2) as seq =>
-
-        when (seq.Location != b.Location)
-          info.Walk(b);
-
-        info.Walk(e2);
-
-      //| Sequence(e1, e2)                  => // { mutable e1 : TExpr; mutable e2 : TExpr; }
-
-      //  info.Walk(e1);
-      //  info.Walk(e2);
-
-      | Delayed(susp)                     => // { susp : Typer.DelayedTyping; }
-
-        unless (susp.IsResolved)
-          susp.Resolve();
-
-      | HasType as ht                     => // { expr : TExpr; test_ty : MType; }
-
-        info.Walk(ht.expr);
-        CheckObject(ht.Location, ht.test_ty);
-
-      | TypeOf as to                      => // { target_type : TyVar; }
-
-        CheckObject(to.Location, to.target_type);
-
-      | _ => ()
+    | Base                (o : object)         // { base_ctor : IMethod; }
+    | LocalFunRef         (o : object, _)      // { decl : LocalValue; type_parms : list [TyVar]; }
+    | LocalRef            (o : object)         // { decl : LocalValue; }
+    | MethodRef        (_, o : object, _, _)   // { obj : TExpr; meth : IMethod; type_parms : list [TyVar]; notvirtual : bool; }
+    | EventMember      (_, o : object)         // { obj : TExpr; ev : IEvent; }
+    | FieldMember      (_, o : object)         // { obj : TExpr; fld : IField; }
+    | PropertyMember   (_, o : object)         // { obj : TExpr; prop : IProperty; }
+    | TypeConversion   (_, o : object, _)      // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
+    | DefValIn            (o : object, _, _)   // { name : LocalValue; val : TExpr; mutable body : TExpr; }
+    | HasType          (_, o : object)         // { expr : TExpr; test_ty : MType; }
+    | TypeOf              (o : object) => o    // { target_type : TyVar; }
+    | _                                => expression
+    }
+
+    IgnoreTExpr(obj : object) : bool
+    {
+      match (obj)
+      {
+      | pat is Pattern =>
+
+        match (pat)
+        {
+        | Record   => _texprObject is Pattern.Application
+        | Wildcard => _texprObject is Pattern.Application || _texprObject is Pattern.As
+        | HasType  => _texprObject is Pattern.As && (_texprObject :> Pattern.As).decl.Name == PExprName
+        | _        => false
+        }
+      | _ => false
       }
     }
 
     TFinder(info : ExprWalkInfo) : void
     {
-      when (info.Node is TExpr.Literal || info.Node is Pattern.Literal || !IsIn(_curLocation))
-        return;
-
       when (info.Node is Located)
-        Print(info.Node :> Located, info.Nodes.Length);
-
-      match (info.Node)
       {
-      | pat  is Pattern      => FindPattern(pat,  info)
-      | expr is TExpr        => FindExpr   (expr, info);
-      | hdr  is T.Fun_header =>
+        def loc = (info.Node :> Located).Location;
 
-        when (IsIn(hdr.Location))
+        when (IsIn(loc))
         {
-          foreach (p in hdr.parms)
-            CheckObject(p.Location, p.decl);
+          Print(info.Node, loc, info.Nodes.Length);
 
-          CheckLocated(hdr);
-          info.Skip();
-        }
+          when (
+            if      (_texprObject == null)  true
+            else if (loc == _texprLocation) !IgnoreTExpr(info.Node)
+            else 
+               loc == _pexprLocation ||
+               loc == _texprLocation.Intersect(loc)
+          )
+          {
+            PrintAdd(info.Nodes.Length);
 
-      | _ => ()
+            _texprLocation = loc;
+            _texprObject   = info.Node;
       }
 
-      when (_stop)
+          when (_pexprObject is PExpr.MacroCall && loc == _pexprLocation)
         info.Stop();
     }
-
-    public Find(
-      root          : TExpr,
-      line          : int,
-      col           : int,
-      pexprLocation : Location,
-      findLocation  : bool
-    )
-      : Location * object
-    {
-      Init(root.Location, line, col);
-
-      _pexprLocation = pexprLocation;
-      _findLocation  = findLocation;
-
-      ExprWalker().Walk(root, TFinder);
-
-      (_retLocation, _retObject)
+      }
     }
 
-    #endregion
-
-    #region Find Token
-
-    Go(token : Token, stack : list[Token]) : list[Token]
+    public Find(pRoot : PExpr, tRoot : TExpr, line : int, col : int) : Location * object * object
     {
-      when (_stop || token == null)
-        return stack;
+      Init(line, col);
 
-      Print(token, token.Location, _counter);
-      _counter++;
+      ExprWalker().Walk(pRoot, PFinder);
 
-      mutable newStack = match (token)
+      if (_pexprObject != null)
       {
-      | RoundGroup (child)    // {         Child : Token; } // ( ... )
-      | BracesGroup(child)    // {         Child : Token; } // { ... }
-      | SquareGroup(child)    // { mutable Child : Token; } // [ ... ]
-      | QuoteGroup (child)    // {         Child : Token; } // <[ ... ]>
-      | LooseGroup (child)    // { mutable Child : Token; } // ; ... ;
-      | Namespace(_,child) => // { Env : GlobalEnv; Body : Token; }
-
-        //if (IsIn(token.Location))
-          Go(child, token :: stack)
-        //else
-        //  stack
-
-      | _ =>
-
-        stack
+#if PRINT_AST
+        Trace.WriteLine("");
+        Trace.WriteLine($"PExpr: $(_pexprLocation.Line):$(_pexprLocation.Column):"
+          "$(_pexprLocation.EndLine):$(_pexprLocation.EndColumn) $_line:$_col.");
+        Trace.WriteLine($"$_pexprObject");
+#endif
 
-      }
+        ExprWalker().Walk(tRoot, TFinder);
 
-      _counter--;
+        (
+          _pexprLocation,
+          _pexprObject,
+          match (_texprObject)
+          {
+          | pat  is Pattern      => GetPattern(pat)
+          | expr is TExpr        => GetExpr   (expr);
+          /*| hdr  is T.Fun_header =>
 
-      unless (_stop)
+            when (IsIn(hdr.Location))
       {
-        _stop = IsIn(token.Location);
+              foreach (p in hdr.parms)
+                CheckObject(p.Location, p.decl);
 
-        unless (_stop)
-          newStack = Go(token.Next, newStack);
+              CheckLocated(hdr);
+              info.Skip();
       }
-
-      if (_stop) (newStack) else (stack);
+          */
+          | _ => _texprObject
     }
-
-    public Find(
-      root : Token,
-      line : int,
-      col  : int
     )
-      : list[Token]
+      }
+      else
     {
-      Init(root.Location, line, col);
-
-      Go(root, [])
+        (Location.Default, null, null)
+      }
     }
 
-    #endregion
-
-    #region Helpers
-
-    Init(rootLocation : Location, line : int, col : int) : void
+    Init(line : int, col : int) : void
     {
 #if PRINT_AST
       Trace.WriteLine($"\nStart at: $line:$col.");
 #endif
 
-      _curLocation = Location(
-        rootLocation.FileIndex,
-        rootLocation.Line,
-        rootLocation.Column,
-        line + 100,
-        1);
-
       _line        = line;
       _col         = col;
-      _counter     = 0;
       _stop        = false;
-      _retObject   = null;
-      _retLocation = Location.Default;
+      _pexprObject   = null;
+      _texprObject   = null;
     }
 
     IsIn(location : Location) : bool
@@ -342,49 +213,24 @@
       location.Contains(_line, _col);
     }
 
-    CheckObject(location : Location, obj : object) : void
-    {
-      unless (_stop)
-      {
-        if (IsIn(location))
-        {
-          _stop        = true;
-          _retObject   = obj;
-          _retLocation = _curLocation.Intersect(location);
-        }
-        else
-        {
-          _curLocation = _curLocation.Trim(location, _line, _col);
-        }
-      }
-    }
-
-    CheckLocated(obj : Located) : void
+    Print(obj : object, loc : Location, level : int) : void
     {
-      CheckObject(obj.Location, obj);
-    }
+#if PRINT_AST
+      mutable s = "";
 
-    Check(l1 : Location, f1 : void -> void, l2 : Location, f2 : void -> void) : void
-    {
-      if (IsIn(l1) && IsIn(l2))
-      {
-        def loc = l1.Intersect(l2);
+      for (mutable i = 0; i < level; i++)
+        s += "  ";
 
-        if (loc == l1) { f1(); unless (_stop) f2(); }
-        else           { f2(); unless (_stop) f1(); }
-      }
-      else
-      {
-        f1(); unless (_stop) f2();
-      }
-    }
+      Trace.WriteLine("");
+      Trace.WriteLine(s + $"$(obj.GetType().FullName) $(loc.Line):$(loc.Column):"
+        "$(loc.EndLine):$(loc.EndColumn) $_line:$_col.");
+      Trace.WriteLine(s + obj.ToString().Replace("\n", "\n" + s));
+#endif
 
-    Print(ex : Located, level : int) : void
-    {
-      Print(ex, ex.Location, level);
+      ignore(obj); ignore(loc); ignore(level);
     }
 
-    Print(obj : object, loc : Location, level : int) : void
+    PrintAdd(level : int) : void
     {
 #if PRINT_AST
       mutable s = "";
@@ -392,18 +238,10 @@
       for (mutable i = 0; i < level; i++)
         s += "  ";
 
-      Trace.WriteLine(s + $"$(obj.GetType().FullName) $(loc.Line):$(loc.Column):"
-        "$(loc.EndLine):$(loc.EndColumn) "
-        "cur:$(_curLocation.Line):$(_curLocation.Column):"
-        "$(_curLocation.EndLine):$(_curLocation.EndColumn) "
-        "$_line:$_col.");
-      Trace.WriteLine(s + obj.ToString().Replace("\n", "\n" + s));
-      Trace.WriteLine("");
+      Trace.WriteLine(s + "+");
 #endif
 
-      ignore(obj); ignore(loc); ignore(level);
+      ignore(level);
     }
-
-    #endregion
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	Sun Oct 29 06:15:12 2006
@@ -78,7 +78,7 @@
       col       : int,
       source    : ISourceTextManager
     )
-      : Location * object
+      : Location * object * object
     {
       def typeBuilder = typeDecl.Builder;
       def member      = 
@@ -97,6 +97,10 @@
 
           def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, loc);
 
+
+          ExprFinder().Find(pBody, tBody, line, col);
+
+          /*
           def (pLoc, pExpr, findLocation) = if (pBody != null)
           {
             def (pLoc, pObj) = ExprFinder().Find(pBody, line, col);
@@ -124,6 +128,7 @@
           }
           else
             (Location.Default, null)
+          */
         }
         else
         {
@@ -139,13 +144,13 @@
             //array(0); // completion outside body (try conplete types)
           }
           */
-          (Location.Default, null)
+          (Location.Default, null, null)
         }
 
-      | fb is FieldBuilder    => (fb.Location,      fb)
-      | pb is PropertyBuilder => (pb.Location,      pb)
-      | tb is TypeBuilder     => (tb.Location,      tb)
-      | null                  => (Location.Default, null)
+      | fb is FieldBuilder    => (fb.Location,      null, fb)
+      | pb is PropertyBuilder => (pb.Location,      null, pb)
+      | tb is TypeBuilder     => (tb.Location,      null, tb)
+      | null                  => (Location.Default, null, null)
       | _                     =>
         Trace.Assert(false, $"Unknown member type '$member'.");
         throw System.Exception($"Unknown member type '$member'.");
@@ -161,11 +166,14 @@
     )
       : QuickTipInfo
     {
-      def (loc, obj) = FindObject(typeDecl, fileIndex, line, col, source);
+      def (loc, pObj, tObj) = FindObject(typeDecl, fileIndex, line, col, source);
 
-      match (obj)
+      match (tObj)
       {
-      | mc is (PExpr.MacroCall * TExpr) => (QuickTipInfo(loc, mc[0], mc[1]))
+      | mc is TExpr when pObj is PExpr.MacroCall =>
+
+        (QuickTipInfo(loc, pObj :> PExpr.MacroCall, mc))
+
       | lv is LocalValue                => (QuickTipInfo(loc,         lv))
       | mm is IMember                   => (QuickTipInfo(loc,         mm))
       | tv is TyVar                     => (QuickTipInfo(loc,         tv))
@@ -186,11 +194,14 @@
     )
       : GotoInfo
     {
-      def (_, obj) = FindObject(typeDecl, fileIndex, line, col, source);
+      def (_, pObj, tObj) = FindObject(typeDecl, fileIndex, line, col, source);
 
-      match (obj)
+      match (tObj)
       {
-      | mc is (PExpr.MacroCall * TExpr) => (GotoInfo(mc[0], mc[1]))
+      | mc is TExpr when pObj is PExpr.MacroCall =>
+
+        (GotoInfo(pObj :> PExpr.MacroCall, mc))
+
       | lv is LocalValue                => (GotoInfo(lv))
       | mm is IMember                   => (GotoInfo(mm))
       | tv is TyVar                     => (GotoInfo(tv))
@@ -224,7 +235,7 @@
           {
             def bodyCode = source.GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
             def groups   = _engine.PreParse(bodyCode, loc);
-            def tokens   = ExprFinder().Find(groups, line, col);
+            def tokens   = TokenFinder().Find(groups, line, col);
 
             match (tokens.Find(t => t is Token.RoundGroup))
             {

Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/TokenFinder.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/TokenFinder.n	Sun Oct 29 06:15:12 2006
@@ -0,0 +1,127 @@
+using System;
+using System.Diagnostics;
+
+using Nemerle.Compiler;
+using Nemerle.Compiler.Utils;
+using Nemerle.Imperative;
+
+namespace Nemerle.Completion2
+{
+  class TokenFinder
+  {
+    mutable _line          : int;
+    mutable _col           : int;
+    mutable _counter       : int;
+    mutable _curLocation   : Location;
+    mutable _retObject     : object;
+    mutable _retLocation   : Location;
+    mutable _stop          : bool;
+
+    #region Find Token
+
+    Go(token : Token, stack : list[Token]) : list[Token]
+    {
+      when (_stop || token == null)
+        return stack;
+
+      Print(token, token.Location, _counter);
+      _counter++;
+
+      mutable newStack = match (token)
+      {
+      | RoundGroup (child)    // {         Child : Token; } // ( ... )
+      | BracesGroup(child)    // {         Child : Token; } // { ... }
+      | SquareGroup(child)    // { mutable Child : Token; } // [ ... ]
+      | QuoteGroup (child)    // {         Child : Token; } // <[ ... ]>
+      | LooseGroup (child)    // { mutable Child : Token; } // ; ... ;
+      | Namespace(_,child) => // { Env : GlobalEnv; Body : Token; }
+
+        //if (IsIn(token.Location))
+          Go(child, token :: stack)
+        //else
+        //  stack
+
+      | _ =>
+
+        stack
+
+      }
+
+      _counter--;
+
+      unless (_stop)
+      {
+        _stop = IsIn(token.Location);
+
+        unless (_stop)
+          newStack = Go(token.Next, newStack);
+      }
+
+      if (_stop) (newStack) else (stack);
+    }
+
+    public Find(
+      root : Token,
+      line : int,
+      col  : int
+    )
+      : list[Token]
+    {
+      Init(root.Location, line, col);
+
+      Go(root, [])
+    }
+
+    #endregion
+
+    #region Helpers
+
+    Init(rootLocation : Location, line : int, col : int) : void
+    {
+#if PRINT_AST
+      Trace.WriteLine($"\nStart at: $line:$col.");
+#endif
+
+      _curLocation = Location(
+        rootLocation.FileIndex,
+        rootLocation.Line,
+        rootLocation.Column,
+        line + 100,
+        1);
+
+      _line        = line;
+      _col         = col;
+      _counter     = 0;
+      _stop        = false;
+      _retObject   = null;
+      _retLocation = Location.Default;
+    }
+
+    IsIn(location : Location) : bool
+    {
+      location.Contains(_line, _col);
+    }
+
+    Print(obj : object, loc : Location, level : int) : void
+    {
+#if PRINT_AST
+      mutable s = "";
+
+      for (mutable i = 0; i < level; i++)
+        s += "  ";
+
+      Trace.WriteLine(s + $"$(obj.GetType().FullName) $(loc.Line):$(loc.Column):"
+        "$(loc.EndLine):$(loc.EndColumn) "
+        "cur:$(_curLocation.Line):$(_curLocation.Column):"
+        "$(_curLocation.EndLine):$(_curLocation.EndColumn) "
+        "$_line:$_col.");
+      Trace.WriteLine(s + obj.ToString().Replace("\n", "\n" + s));
+      Trace.WriteLine("");
+#endif
+
+      ignore(obj); ignore(loc); ignore(level);
+    }
+
+    #endregion
+  }
+}



More information about the svn mailing list