--- a/Parser.st Thu Oct 04 16:19:46 2001 +0200
+++ b/Parser.st Tue Oct 09 09:41:57 2001 +0200
@@ -2610,63 +2610,71 @@
"collect known variables with their spelling distances to aString;
return the 10 best suggestions"
- |names dists searchBlock args vars globalVarName "aClass className baseClass"
- n instVarNames classVarNames|
+ |names dists searchBlock args vars "aClass className baseClass"
+ n instVarNames classVarNames spellAgainstAction|
names := OrderedCollection new.
dists := OrderedCollection new.
+ spellAgainstAction :=
+ [:aVarNode |
+ |varName dist|
+
+ varName := aVarNode name.
+ names add:varName.
+
+ dist := aString spellAgainst:varName.
+ (aString startsWith:varName) ifTrue:[
+ dist := dist + (aString size * 10).
+ ].
+ dists add:dist
+ ].
+
"block arguments"
searchBlock := currentBlock.
[searchBlock notNil] whileTrue:[
args := searchBlock arguments.
args notNil ifTrue:[
- args do:[:aBlockArg |
- names add:(aBlockArg name).
- dists add:(aString spellAgainst: "levenshteinTo:"(aBlockArg name))
- ]
+ args do:spellAgainstAction
].
vars := searchBlock variables.
vars notNil ifTrue:[
- vars do:[:aBlockVar |
- names add:(aBlockVar name).
- dists add:(aString spellAgainst: "levenshteinTo:"(aBlockVar name))
- ]
+ vars do:spellAgainstAction
].
searchBlock := searchBlock home
].
+ spellAgainstAction :=
+ [:givenName |
+ |dist|
+
+ names add:givenName.
+ dist := aString spellAgainst:givenName.
+ (aString startsWith:givenName) ifTrue:[
+ dist := dist + (aString size * 10).
+ ].
+ dists add:dist
+ ].
+
"method-variables"
methodVars notNil ifTrue:[
- methodVarNames do:[:methodVarName |
- names add:methodVarName.
- dists add:(aString spellAgainst: "levenshteinTo:"methodVarName)
- ]
+ methodVarNames do:spellAgainstAction
].
"method-arguments"
methodArgs notNil ifTrue:[
- methodArgNames do:[:methodArgName |
- names add:methodArgName.
- dists add:(aString spellAgainst: "levenshteinTo:"methodArgName)
- ]
+ methodArgNames do:spellAgainstAction
].
"instance-variables"
classToCompileFor notNil ifTrue:[
- self classesInstVarNames do:[:instVarName |
- names add:instVarName.
- dists add:(aString spellAgainst: "levenshteinTo:"instVarName)
- ]
+ self classesInstVarNames do:spellAgainstAction
].
"class-variables"
classToCompileFor notNil ifTrue:[
- self classesClassVarNames do:[:classVarName |
- names add:classVarName.
- dists add:(aString spellAgainst: "levenshteinTo:"classVarName)
- ].
+ self classesClassVarNames do:spellAgainstAction.
"/ aClass := classToCompileFor.
"/ aClass isMeta ifTrue:[
@@ -2689,19 +2697,18 @@
"globals"
Smalltalk keysDo:[:aKey |
+ |globalVarName|
+
globalVarName := aKey asString.
+
"only compare strings where length is about right"
((globalVarName size - aString size) abs < 3) ifTrue:[
- names add:globalVarName.
- dists add:(aString spellAgainst: "levenshteinTo:"globalVarName)
+ spellAgainstAction value:globalVarName.
]
].
"misc"
- #('self' 'super' 'nil' 'thisContext') do:[:name |
- names add:name.
- dists add:(aString spellAgainst: "levenshteinTo:"name)
- ].
+ #('self' 'super' 'nil' 'thisContext') do:spellAgainstAction.
(dists size ~~ 0) ifTrue:[
dists sortWith:names.
@@ -5980,6 +5987,6 @@
!Parser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.304 2001-10-04 14:19:46 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.305 2001-10-09 07:41:57 cg Exp $'
! !
Parser initialize!