[svn] r7231: nemerle/trunk: lib/narray.n ncc/parsing/AST.n
VladD2
svnadmin at nemerle.org
Tue Jan 9 10:39:07 CET 2007
Log:
Add IndexOfMostNested method to Location.
Author: VladD2
Date: Tue Jan 9 10:39:04 2007
New Revision: 7231
Modified:
nemerle/trunk/lib/narray.n
nemerle/trunk/ncc/parsing/AST.n
Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n (original)
+++ nemerle/trunk/lib/narray.n Tue Jan 9 10:39:04 2007
@@ -33,7 +33,11 @@
{
public module NCollectionsUtils
{
- public FoldLeft [A, B] (this source : SCG.IEnumerable [B], mutable ini : A, f : B * A -> A) : A
+ public FoldLeft [TAccumulator, T] (
+ this source : SCG.IEnumerable [T],
+ mutable ini : TAccumulator, f : T * TAccumulator -> TAccumulator
+ )
+ : TAccumulator
{
foreach (value in source)
ini = f(value, ini);
@@ -41,7 +45,11 @@
ini
}
- public FoldRight [A, B] (this source : SCG.IEnumerable [B], mutable ini : A, f : B * A -> A) : A
+ public FoldRight [TAccumulator, T] (
+ this source : SCG.IEnumerable [T],
+ mutable ini : TAccumulator, f : T * TAccumulator -> TAccumulator
+ )
+ : TAccumulator
{
def ary = source.ToArray ();
for (mutable i = ary.Length - 1; i <= 0; i--)
@@ -50,7 +58,11 @@
ini
}
- public Fold [A, B] (this source : SCG.IEnumerable [B], mutable ini : A, f : B * A -> A) : A
+ public Fold [TAccumulator, T] (
+ this source : SCG.IEnumerable [T],
+ mutable ini : TAccumulator, f : T * TAccumulator -> TAccumulator
+ )
+ : TAccumulator
{
FoldLeft (source, ini, f)
}
Modified: nemerle/trunk/ncc/parsing/AST.n
==============================================================================
--- nemerle/trunk/ncc/parsing/AST.n (original)
+++ nemerle/trunk/ncc/parsing/AST.n Tue Jan 9 10:39:04 2007
@@ -414,6 +414,45 @@
{
EndLine == 0 || EndLine < Line || (EndLine == Line && EndColumn <= Column)
}
+
+ /// True if second contain inside this location and them not equal.
+ public IsNestedIn(second : Location) : bool
+ {
+ second.StrictlyContains(this)
+ }
+
+ public static IndexOfMostNested2[T](
+ this seq : SCG.IList[T],
+ convert : System.Converter[T, Location],
+ line : int,
+ col : int
+ )
+ : int
+ {
+ IndexOfMostNested(seq, convert(_), line, col)
+ }
+
+ /// Return index of object in seq which conain most nested Lication.
+ public static IndexOfMostNested[T](
+ this seq : SCG.IList[T],
+ convert : T -> Location,
+ line : int,
+ col : int
+ )
+ : int
+ {
+ def (_, resIndex, _) = seq.Fold((0, -1, Location.Default),
+ fun(elem, (i, resIndex, curr))
+ {
+ def loc = convert(elem);
+ if (loc.Contains(line, col) && (resIndex < 0 || loc.IsNestedIn(curr)))
+ (i + 1, i, loc)
+ else
+ (i + 1, resIndex, curr);
+ });
+
+ resIndex
+ }
}
public class Located
More information about the svn
mailing list