*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Mon, 24 Sep 2001 10:03:34 +0200
changeset 1187 902d406b9100
parent 1186 014c3db76517
child 1188 8c0408dc39f2
*** empty log message ***
Parser.st
--- a/Parser.st	Wed Sep 19 12:56:48 2001 +0200
+++ b/Parser.st	Mon Sep 24 10:03:34 2001 +0200
@@ -482,6 +482,87 @@
     "Created: 14.2.1997 / 16:52:54 / cg"
 ! !
 
+!Parser class methodsFor:'error correction'!
+
+findBestSelectorsFor:aString
+    "collect known selectors with their spelling distances to aString;
+     return the 10 best suggestions"
+
+    |info n|
+
+    info := SortedCollection new.
+    info sortBlock:[:a :b | a value > b value].
+
+    n := 0.
+
+    Symbol allInstancesDo:[:sym |
+        |dist|
+
+        dist := aString spellAgainst:sym.
+        dist > 20 ifTrue:[
+            info add:(sym -> dist).
+            n := n + 1.
+            n > 10 ifTrue:[
+                info removeLast.
+            ]
+        ]
+    ].
+
+    ^ info asOrderedCollection collect:[:a | a key]
+
+    "Time millisecondsToRun:[Parser new findBestSelectorsFor:'foo']"
+    "Parser new findBestSelectorsFor:'findBestSel'"
+    "Parser new findBestSelectorsFor:'fildBestSelectrFr'"
+!
+
+findBestSelectorsFor:aString in:aClassOrNil
+    "collect known selectors with their spelling distances to aString;
+     return the 10 best suggestions. If the argument, aClassOrNil is not nil,
+     the message is assumed to be sent to instances of that class (i.e. offer
+     corrections from that hierarchy only)"
+
+    |info n block lcSelector|
+
+    info := SortedCollection new.
+    info sortBlock:[:a :b | a value > b value].
+
+    n := 0.
+
+    lcSelector := aString asLowercase.
+
+    block := [:sym :mthd|
+        |dist lcSym|
+
+        lcSym := sym asLowercase.
+        (info contains:[:i | i key == sym]) ifFalse:[
+            dist := lcSelector spellAgainst:lcSym.
+            (dist > 20 and:[mthd isObsolete not]) ifTrue:[
+                info add:(sym -> dist).
+                n := n + 1.
+                n > 10 ifTrue:[
+                    info removeLast.
+                ]
+            ]
+        ]
+    ].
+
+    aClassOrNil isNil ifTrue:[
+        Smalltalk allClassesDo:[:cls |
+            cls methodDictionary keysAndValuesDo:block.
+            cls class methodDictionary keysAndValuesDo:block.
+        ]
+    ] ifFalse:[
+        aClassOrNil withAllSuperclassesDo:[:cls |
+            cls methodDictionary keysAndValuesDo:block.
+            cls class methodDictionary keysAndValuesDo:block.
+        ]
+    ].
+
+    ^ info asOrderedCollection collect:[:a | a key]
+
+    "Modified: / 19.1.2000 / 16:43:37 / cg"
+! !
+
 !Parser class methodsFor:'evaluating expressions'!
 
 evaluate:aStringOrStream
@@ -2500,27 +2581,7 @@
     "collect known selectors with their spelling distances to aString;
      return the 10 best suggestions"
 
-    |info n|
-
-    info := SortedCollection new.
-    info sortBlock:[:a :b | a value > b value].
-
-    n := 0.
-
-    Symbol allInstancesDo:[:sym |
-	|dist|
-
-	dist := aString spellAgainst:sym.
-	dist > 20 ifTrue:[
-	    info add:(sym -> dist).
-	    n := n + 1.
-	    n > 10 ifTrue:[
-		info removeLast.
-	    ]
-	]
-    ].
-
-    ^ info asOrderedCollection collect:[:a | a key]
+    ^ self class findBestSelectorsFor:aString 
 
     "Time millisecondsToRun:[Parser new findBestSelectorsFor:'foo']"
     "Parser new findBestSelectorsFor:'findBestSel'"
@@ -2533,46 +2594,7 @@
      the message is assumed to be sent to instances of that class (i.e. offer
      corrections from that hierarchy only)"
 
-    |info n block lcSelector|
-
-    info := SortedCollection new.
-    info sortBlock:[:a :b | a value > b value].
-
-    n := 0.
-
-    lcSelector := aString asLowercase.
-
-    block := [:sym :mthd|
-        |dist lcSym|
-
-        lcSym := sym asLowercase.
-        (info contains:[:i | i key == sym]) ifFalse:[
-            dist := lcSelector spellAgainst:lcSym.
-            (dist > 20 and:[mthd isObsolete not]) ifTrue:[
-                info add:(sym -> dist).
-                n := n + 1.
-                n > 10 ifTrue:[
-                    info removeLast.
-                ]
-            ]
-        ]
-    ].
-
-    aClassOrNil isNil ifTrue:[
-        Smalltalk allClassesDo:[:cls |
-            cls methodDictionary keysAndValuesDo:block.
-            cls class methodDictionary keysAndValuesDo:block.
-        ]
-    ] ifFalse:[
-        aClassOrNil withAllSuperclassesDo:[:cls |
-            cls methodDictionary keysAndValuesDo:block.
-            cls class methodDictionary keysAndValuesDo:block.
-        ]
-    ].
-
-    ^ info asOrderedCollection collect:[:a | a key]
-
-    "Modified: / 19.1.2000 / 16:43:37 / cg"
+    ^ self class findBestSelectorsFor:aString in:aClassOrNil
 !
 
 findBestVariablesFor:aString
@@ -5932,6 +5954,6 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.297 2001-09-19 10:55:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.298 2001-09-24 08:03:34 cg Exp $'
 ! !
 Parser initialize!