author | Claus Gittinger <cg@exept.de> |
Wed, 24 Jul 2002 12:17:38 +0200 | |
changeset 1289 | 2434f1ee11ee |
parent 1256 | cc3fa02585ec |
child 1316 | 30806ca08095 |
permissions | -rw-r--r-- |
2 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
49 | 3 |
All Rights Reserved |
2 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1081 | 13 |
"{ Package: 'stx:libcomp' }" |
14 |
||
141 | 15 |
Parser subclass:#Explainer |
263 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'System-Compiler' |
|
2 | 20 |
! |
21 |
||
396 | 22 |
!Explainer class methodsFor:'documentation'! |
2 | 23 |
|
20 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
49 | 27 |
All Rights Reserved |
20 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
2 | 38 |
documentation |
39 |
" |
|
20 | 40 |
a very simple explainer - much more should be added ... |
41 |
This one is involved, when the 'explain' function is used in a |
|
84 | 42 |
codeView (popup or via CMD-E). |
263 | 43 |
|
44 |
[author:] |
|
45 |
Claus Gittinger |
|
2 | 46 |
" |
47 |
! ! |
|
48 |
||
396 | 49 |
!Explainer class methodsFor:'explaining'! |
2 | 50 |
|
141 | 51 |
commonSuperClassOf:listOfClassNames |
52 |
|common found| |
|
53 |
||
54 |
listOfClassNames do:[:className | |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
55 |
|class| |
141 | 56 |
|
336 | 57 |
class := Smalltalk classNamed:className. |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
58 |
common isNil ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
59 |
common := class |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
60 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
61 |
(class isSubclassOf:common) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
62 |
"keep common" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
63 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
64 |
(common isSubclassOf:class) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
65 |
common := class |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
66 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
67 |
"walk up, checking" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
68 |
found := false. |
1151 | 69 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
70 |
common allSuperclassesDo:[:sup | |
1151 | 71 |
(found not and:[class isSubclassOf:sup]) ifTrue:[ |
72 |
common := sup. |
|
73 |
found := true. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
74 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
75 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
76 |
found ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
77 |
class allSuperclassesDo:[:sup | |
1151 | 78 |
(found not and:[common isSubclassOf:sup]) ifTrue:[ |
79 |
common := sup. |
|
80 |
found := true. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
81 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
82 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
83 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
84 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
85 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
86 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
87 |
common == Object ifTrue:[^ common] |
141 | 88 |
]. |
89 |
^ common |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
90 |
|
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
91 |
"Modified: 17.6.1996 / 17:09:21 / stefan" |
336 | 92 |
"Modified: 5.9.1996 / 19:34:41 / cg" |
141 | 93 |
! |
94 |
||
2 | 95 |
explain:someText in:source forClass:aClass |
6 | 96 |
"Given a source and a substring of it, return a string containing |
97 |
an explanation. |
|
49 | 98 |
This is just a q&d implementation - to be correct, it should use the parser, |
99 |
and explain from the parsetree (instead of doing string matches). |
|
100 |
This leads to some wrong explanations, for example if some string is |
|
839 | 101 |
used as selector within a string, or if a variable is named like a |
102 |
message selector. I.e. the explanation should be context sensitive. |
|
49 | 103 |
Also, there could be much more detailed explanations." |
2 | 104 |
|
1183 | 105 |
^ self |
106 |
explain:someText in:source forClass:aClass short:false |
|
107 |
! |
|
108 |
||
109 |
explain:someText in:source forClass:aClass short:shortText |
|
110 |
"Given a source and a substring of it, return a string containing |
|
111 |
an explanation. |
|
112 |
This is just a q&d implementation - to be correct, it should use the parser, |
|
113 |
and explain from the parsetree (instead of doing string matches). |
|
114 |
This leads to some wrong explanations, for example if some string is |
|
115 |
used as selector within a string, or if a variable is named like a |
|
116 |
message selector. I.e. the explanation should be context sensitive. |
|
117 |
Also, there could be much more detailed explanations." |
|
118 |
||
1159 | 119 |
|parser variables c string tmp |
1289 | 120 |
spc sym sel stringText clsName val valString| |
2 | 121 |
|
675 | 122 |
string := someText string withoutSeparators. |
1198 | 123 |
stringText := string allBold. |
1233 | 124 |
stringText := '''' , stringText , ''''. |
49 | 125 |
|
126 |
" |
|
127 |
ask parser for variable names |
|
128 |
" |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
129 |
parser := self parseMethod:source in:aClass ignoreErrors:true ignoreWarnings:true. |
2 | 130 |
parser notNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
131 |
"look for variables" |
2 | 132 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
133 |
variables := parser methodVars. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
134 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 135 |
^ stringText , ' is a method variable.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
136 |
]. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
137 |
variables := parser methodArgs. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
138 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 139 |
^ stringText , ' is a method argument.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
140 |
] |
2 | 141 |
]. |
49 | 142 |
|
2 | 143 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
144 |
parser := self for:(ReadStream on:source) in:aClass |
2 | 145 |
]. |
146 |
||
147 |
"instvars" |
|
84 | 148 |
c := aClass whichClassDefinesInstVar:string. |
149 |
c notNil ifTrue:[ |
|
396 | 150 |
c isMeta ifTrue:[ |
1211
91e94e294819
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1210
diff
changeset
|
151 |
clsName := c theNonMetaclass name. |
1198 | 152 |
shortText ifTrue:[ |
1233 | 153 |
^ stringText , ' is a class instVar in ' , clsName , '.' |
1198 | 154 |
]. |
1233 | 155 |
^ stringText, ' is a class instance variable in ' , clsName , '.' |
396 | 156 |
]. |
157 |
||
1233 | 158 |
clsName := c name. |
1198 | 159 |
shortText ifTrue:[ |
1233 | 160 |
^ stringText , ' is an instVar in ' , clsName , '.' |
1198 | 161 |
]. |
1233 | 162 |
^ stringText , ' is an instance variable in ' , clsName , '.' |
2 | 163 |
]. |
164 |
||
84 | 165 |
"/ variables := aClass allInstVarNames. |
166 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
167 |
"/ "where is it" |
|
168 |
"/ c := aClass. |
|
1159 | 169 |
"/ [c notNil] whileTrue:[ |v| |
84 | 170 |
"/ v := c instVarNames. |
171 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
172 |
"/ ^ string , ' is an instance variable in ' , c name |
|
173 |
"/ ]. |
|
174 |
"/ c := c superclass |
|
175 |
"/ ]. |
|
176 |
"/ self error:'oops' |
|
177 |
"/ ]. |
|
178 |
||
442 | 179 |
"/ "class instvars" |
180 |
"/ variables := aClass class allInstVarNames. |
|
181 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
182 |
"/ "where is it" |
|
183 |
"/ c := aClass. |
|
1159 | 184 |
"/ [c notNil] whileTrue:[ |v| |
442 | 185 |
"/ v := c class instVarNames. |
186 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
187 |
"/ ^ string , ' is a class instance variable in ' , c name |
|
188 |
"/ ]. |
|
189 |
"/ c := c superclass |
|
190 |
"/ ]. |
|
191 |
"/ self error:'oops' |
|
192 |
"/ ]. |
|
2 | 193 |
|
194 |
"classvars" |
|
195 |
c := parser inWhichClassIsClassVar:string. |
|
196 |
c notNil ifTrue:[ |
|
1233 | 197 |
clsName := c name. |
1198 | 198 |
shortText ifTrue:[ |
1289 | 199 |
stringText := stringText , ' is a classVar in ' , clsName |
200 |
] ifFalse:[ |
|
201 |
stringText := stringText , ' is a class variable in ' , clsName |
|
1198 | 202 |
]. |
1289 | 203 |
val := Smalltalk at:(clsName , ':' , string) asSymbol. |
204 |
(val isBoolean or:[val isNil or:[val isSymbol]]) ifTrue:[ |
|
205 |
valString := val storeString. |
|
206 |
] ifFalse:[ |
|
207 |
valString := val classNameWithArticle. |
|
208 |
]. |
|
209 |
^ stringText , ' (' , valString , ').' |
|
2 | 210 |
]. |
211 |
||
1210
e3174ccbb5bb
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
212 |
c := aClass theNonMetaclass. |
509
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
213 |
c privateClasses do:[:pClass | |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
214 |
(pClass name = string |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
215 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
1233 | 216 |
string := stringText , ' is a private class in ''' , c name , '''.'. |
217 |
shortText ifFalse:[ |
|
1183 | 218 |
string := (string , '\\It is only visible locally.') withCRs |
219 |
]. |
|
220 |
^ string withCRs |
|
422 | 221 |
]. |
222 |
]. |
|
223 |
||
456 | 224 |
(spc := aClass nameSpace) notNil ifTrue:[ |
796 | 225 |
sym := (spc name , '::' , string) asSymbolIfInterned. |
226 |
sym notNil ifTrue:[ |
|
227 |
(Smalltalk at:sym) isBehavior ifTrue:[ |
|
1233 | 228 |
string := stringText , ' is a class in the ''' , spc name , ''' nameSpace.'. |
1183 | 229 |
shortText ifFalse:[ |
230 |
string := (string |
|
796 | 231 |
, '\\It is only visible within this nameSpace.' |
232 |
, '\Access from the outside is possible' |
|
233 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
|
1183 | 234 |
]. |
235 |
^ string withCRs |
|
796 | 236 |
]. |
422 | 237 |
]. |
238 |
]. |
|
239 |
||
796 | 240 |
"/ string knownAsSymbol ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
241 |
"globals & symbols" |
2 | 242 |
|
1183 | 243 |
tmp := self explainKnownSymbol:string inClass:aClass short:shortText. |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
244 |
tmp notNil ifTrue:[ ^ tmp]. |
839 | 245 |
|
246 |
"/ try with added colon ... |
|
247 |
sel := string , ':'. |
|
248 |
Symbol allInstancesDo:[:sym | |
|
249 |
(sym startsWith:sel) ifTrue:[ |
|
1183 | 250 |
tmp := self explainKnownSymbol:sym inClass:aClass short:shortText. |
839 | 251 |
tmp notNil ifTrue:[ ^ tmp]. |
252 |
] |
|
253 |
]. |
|
796 | 254 |
"/ ]. |
2 | 255 |
|
256 |
"try for some obvious things" |
|
1183 | 257 |
tmp := self explainPseudoVariable:string in:aClass short:true. |
2 | 258 |
tmp notNil ifTrue:[ ^ tmp]. |
259 |
||
260 |
"try syntax ..." |
|
261 |
||
1183 | 262 |
tmp := self explainSyntax:string short:shortText. |
49 | 263 |
tmp notNil ifTrue:[ ^ tmp]. |
20 | 264 |
|
1183 | 265 |
shortText ifTrue:[ |
266 |
^ '' |
|
267 |
]. |
|
268 |
||
2 | 269 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
270 |
^ 'parse error - no explanation' |
2 | 271 |
]. |
796 | 272 |
^ 'cannot explain this (could not figure out what this is).' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
273 |
|
675 | 274 |
"Created: / 3.12.1995 / 12:47:37 / cg" |
275 |
"Modified: / 16.4.1997 / 12:46:11 / stefan" |
|
1211
91e94e294819
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1210
diff
changeset
|
276 |
"Modified: / 5.11.2001 / 16:54:23 / cg" |
2 | 277 |
! |
278 |
||
1188 | 279 |
explainGlobal:string inClass:aClass short:shortText |
1183 | 280 |
"return explanation or nil" |
281 |
||
1245 | 282 |
|sym stringText tmp val classCategory| |
141 | 283 |
|
1245 | 284 |
"if not even known as key, its definitely not a global" |
285 |
sym := string asSymbolIfInterned. |
|
796 | 286 |
sym isNil ifTrue:[^ nil]. |
141 | 287 |
|
288 |
"try globals" |
|
1245 | 289 |
(Smalltalk includesKey:sym) ifFalse:[ ^ nil]. |
141 | 290 |
|
1198 | 291 |
stringText := string allBold. |
292 |
||
1245 | 293 |
"/ stringText := '''' , stringText , ''''. |
294 |
tmp := stringText , ' is a global variable.'. |
|
1183 | 295 |
|
1245 | 296 |
val := Smalltalk at:sym. |
297 |
val isBehavior ifTrue:[ |
|
298 |
"/ a class |
|
299 |
classCategory := val category. |
|
300 |
shortText ifTrue:[ |
|
301 |
^ stringText , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
|
302 |
, ' class in the ''' , classCategory , ''' category.'. |
|
303 |
]. |
|
304 |
||
305 |
val name = string ifTrue:[ |
|
1183 | 306 |
tmp := tmp , ' |
1245 | 307 |
' , string , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
308 |
, ' class categorized as ' , classCategory , ' |
|
309 |
in the ''' , val package , ''' package.'. |
|
1183 | 310 |
^ tmp. |
311 |
]. |
|
141 | 312 |
|
1183 | 313 |
tmp := tmp , ' |
314 |
||
1245 | 315 |
' , string , ' is bound to the class ' , val name , |
316 |
' in the ''' , classCategory , ''' category.'. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
317 |
^ tmp. |
141 | 318 |
]. |
319 |
||
1245 | 320 |
shortText ifTrue:[ |
321 |
^ stringText , ' is a global, currently bound to ''' , val classNameWithArticle , '''.'. |
|
322 |
]. |
|
323 |
tmp := tmp , ' |
|
324 |
||
325 |
Its current value is ''' , val classNameWithArticle , '''.'. |
|
326 |
^ tmp. |
|
1188 | 327 |
! |
328 |
||
329 |
explainHereIn:aClass |
|
330 |
^ 'like self, here refers to the object which received the message. |
|
331 |
||
332 |
However, when sending a message to here the search for methods |
|
333 |
implementing this message will start in the defining class (' , aClass name , ') |
|
334 |
instead of the receivers class (' , aClass name , ' or subclass). |
|
335 |
Thus, using here, redefined methods will NOT be reached with a here-send.' |
|
336 |
! |
|
337 |
||
338 |
explainKnownSymbol:string inClass:aClass |
|
339 |
"return explanation or nil" |
|
340 |
||
341 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
342 |
! |
|
343 |
||
344 |
explainKnownSymbol:string inClass:aClass short:shortText |
|
345 |
"return explanation or nil" |
|
346 |
||
347 |
|sym| |
|
348 |
||
349 |
sym := string asSymbolIfInterned. |
|
350 |
sym isNil ifTrue:[^ nil]. |
|
351 |
||
352 |
"try globals" |
|
353 |
||
354 |
(Smalltalk includesKey:sym) ifTrue:[ |
|
355 |
^ self explainGlobal:string inClass:aClass short:shortText |
|
356 |
]. |
|
357 |
||
358 |
^ self explainSelector:string inClass:aClass short:shortText |
|
359 |
! |
|
360 |
||
361 |
explainPseudoVariable:string in:aClass |
|
362 |
"return explanation for the pseudoVariables self, super etc." |
|
363 |
||
364 |
^ self explainPseudoVariable:string in:aClass short:false |
|
365 |
! |
|
366 |
||
367 |
explainPseudoVariable:string in:aClass short:shortText |
|
368 |
"return explanation for the pseudoVariables self, super etc." |
|
369 |
||
370 |
(string = 'self') ifTrue:[ |
|
371 |
^ self explainSelfIn:aClass short:shortText |
|
372 |
]. |
|
373 |
||
374 |
(string = 'super') ifTrue:[ |
|
375 |
shortText ifTrue:[ |
|
376 |
^ '''super'' - message lookup starts in superclass ''' , aClass superclass name , '''.' |
|
377 |
]. |
|
378 |
^ self explainSuperIn:aClass short:shortText |
|
379 |
]. |
|
380 |
||
381 |
(string = 'here') ifTrue:[ |
|
382 |
shortText ifTrue:[ |
|
383 |
^ '''here'' - message lookup always starts in ''' , aClass name , '''.' |
|
384 |
]. |
|
385 |
^ self explainHereIn:aClass |
|
386 |
]. |
|
387 |
||
388 |
(string = 'thisContext') ifTrue:[ |
|
389 |
shortText ifTrue:[ |
|
390 |
^ '''thisContext'' - the current stack frame as an object.' |
|
391 |
]. |
|
392 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
393 |
||
394 |
ThisContext always refers to the context object for the currently executed method or |
|
395 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
396 |
receivers/selectors can be accessed via thisContext.' |
|
397 |
]. |
|
398 |
||
399 |
(string = 'true') ifTrue:[ |
|
400 |
shortText ifTrue:[ |
|
401 |
^ '''true'' - the truth and nothing but the truth.' |
|
402 |
]. |
|
403 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
404 |
||
405 |
True represents logical truth. It is the one and only instance of class True.' |
|
406 |
]. |
|
407 |
||
408 |
(string = 'false') ifTrue:[ |
|
409 |
shortText ifTrue:[ |
|
410 |
^ '''false'' - obvisously not true.' |
|
411 |
]. |
|
412 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
413 |
||
414 |
False represents logical falseness. It is the one and only instance of class False.' |
|
415 |
]. |
|
416 |
||
417 |
(string = 'nil') ifTrue:[ |
|
418 |
shortText ifTrue:[ |
|
419 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
420 |
]. |
|
421 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
422 |
||
423 |
Nil is used for unitialized variables (among other uses). |
|
424 |
Nil is the one and only instance of class UndefinedObject.' |
|
425 |
]. |
|
426 |
^ nil |
|
427 |
! |
|
428 |
||
429 |
explainSelector:string inClass:aClass short:shortText |
|
430 |
"return explanation or nil" |
|
431 |
||
432 |
|sym list count tmp commonSuperClass val s s2 |
|
433 |
firstImplementingClass cm msg t| |
|
434 |
||
435 |
sym := string asSymbolIfInterned. |
|
436 |
sym isNil ifTrue:[^ nil]. |
|
437 |
||
141 | 438 |
" |
439 |
try selectors |
|
440 |
look who implements it |
|
441 |
" |
|
442 |
list := Set new. |
|
1081 | 443 |
Smalltalk allClassesDo:[:c| |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
444 |
(c includesSelector:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
445 |
list add:(c name). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
446 |
firstImplementingClass isNil ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
447 |
firstImplementingClass := c |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
448 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
449 |
]. |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
450 |
(c class includesSelector:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
451 |
list add:(c name , ' class'). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
452 |
firstImplementingClass isNil ifTrue:[ |
912 | 453 |
firstImplementingClass := c class |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
454 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
455 |
] |
141 | 456 |
]. |
457 |
||
835 | 458 |
(aClass canUnderstand:sym) ifTrue:[ |
1184 | 459 |
s2 := ('Instances of ''' , aClass name , ''' respond to #') , sym asText allBold , '.'. |
460 |
shortText ifFalse:[ |
|
461 |
s2 := '\\' , s2 |
|
462 |
, '\- inherited from ' withCRs |
|
463 |
, (aClass whichClassImplements:sym) name asText allBold. |
|
464 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
465 |
firstImplementingClass := (aClass whichClassImplements:sym) |
835 | 466 |
] ifFalse:[ |
467 |
s2 := ''. |
|
468 |
]. |
|
469 |
||
141 | 470 |
count := list size. |
471 |
(count ~~ 0) ifTrue:[ |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
472 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
473 |
for up-to 4 implementing classes, |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
474 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
475 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
476 |
list := list asOrderedCollection sort. |
1185 | 477 |
shortText ifTrue:[ |
478 |
tmp := ' is implemented in '. |
|
479 |
] ifFalse:[ |
|
480 |
tmp := ' is a selector implemented in '. |
|
481 |
]. |
|
835 | 482 |
s := '#' , string asText allBold. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
483 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
484 |
(count == 1) ifTrue:[ |
1183 | 485 |
(t := list first) isMeta ifTrue:[ |
486 |
t := 'the ' , t |
|
487 |
]. |
|
1184 | 488 |
msg := s , tmp , t , '.'. |
489 |
shortText ifFalse:[ |
|
490 |
msg := msg , s2. |
|
491 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
492 |
] ifFalse:[ |
1185 | 493 |
(count == 2) ifTrue:[ |
494 |
msg := s , tmp , (list at:1) , ' and ' , (list at:2) , '.'. |
|
495 |
shortText ifFalse:[ |
|
496 |
msg := msg , s2. |
|
497 |
]. |
|
498 |
] ifFalse:[ |
|
499 |
shortText ifTrue:[ |
|
500 |
msg := s , tmp , count printString , ' classes.'. |
|
501 |
^ msg |
|
502 |
]. |
|
1183 | 503 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
504 |
(count == 3) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
505 |
msg := s , tmp , ' |
835 | 506 |
' , (list at:1) , ', ' , (list at:2) , ' and ' , (list at:3) , '.' , s2 |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
507 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
508 |
(count == 4) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
509 |
msg := s , tmp , ' |
835 | 510 |
' , (list at:1) , ', ' , (list at:2) , ', ' , (list at:3), ' and ' , (list at:4) , '.' , s2 |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
511 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
512 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
513 |
if there are more, look for a common |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
514 |
superclass and show it ... |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
515 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
516 |
commonSuperClass := self commonSuperClassOf:list. |
913 | 517 |
(commonSuperClass ~~ Object |
518 |
and:[commonSuperClass ~~ Behavior |
|
519 |
and:[commonSuperClass ~~ Class |
|
520 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
521 |
(list includes:commonSuperClass) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
522 |
msg := s . tmp , count printString , commonSuperClass name |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
523 |
, ' and redefined in ' , (count - 1) printString |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
524 |
, ' subclasses' |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
525 |
, s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
526 |
firstImplementingClass := commonSuperClass |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
527 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
528 |
msg := s , tmp, count printString , ' subclasses of ' , commonSuperClass name , s2 |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
529 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
530 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
531 |
(commonSuperClass == Object |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
532 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
533 |
msg := s , tmp , count printString , ' classes. |
834 | 534 |
|
535 |
All objects seem to respond to that message, |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
536 |
since there is an implementation in Object.' , s2. |
141 | 537 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
538 |
firstImplementingClass := Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
539 |
] ifFalse:[ |
913 | 540 |
((commonSuperClass == Behavior |
541 |
or:[commonSuperClass == Class |
|
542 |
or:[commonSuperClass == ClassDescription]]) |
|
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
543 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
913 | 544 |
msg := s , tmp , count printString , ' classes. |
545 |
||
546 |
All classes seem to respond to that message, |
|
547 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
|
548 |
||
549 |
firstImplementingClass := commonSuperClass |
|
550 |
] ifFalse:[ |
|
551 |
" |
|
552 |
otherwise just give the number. |
|
553 |
" |
|
554 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
555 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
556 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
557 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
558 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
559 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
560 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
561 |
]. |
1185 | 562 |
shortText ifFalse:[ |
563 |
firstImplementingClass notNil ifTrue:[ |
|
564 |
WindowGroup activeGroup withWaitCursorDo:[ |
|
565 |
cm := firstImplementingClass compiledMethodAt:sym. |
|
566 |
cm notNil ifTrue:[ |
|
567 |
cm := cm methodComment. |
|
568 |
] |
|
569 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
570 |
cm notNil ifTrue:[ |
1185 | 571 |
msg := msg , '\\The comment in ' withCRs , firstImplementingClass name allBold , ' is:\' withCRs , cm allItalic. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
572 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
573 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
574 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
575 |
^ msg |
141 | 576 |
]. |
577 |
||
578 |
^ nil |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
579 |
|
796 | 580 |
"Modified: / 17.6.1996 / 17:09:30 / stefan" |
835 | 581 |
"Created: / 23.3.1999 / 13:29:33 / cg" |
582 |
"Modified: / 23.3.1999 / 13:40:40 / cg" |
|
141 | 583 |
! |
584 |
||
1183 | 585 |
explainSelfIn:aClass short:shortText |
1244 | 586 |
|sub subNames selfString className nSubClasses| |
1198 | 587 |
|
588 |
selfString := '''' , 'self' allBold , ''''. |
|
6 | 589 |
|
1244 | 590 |
sub := aClass allSubclasses. |
591 |
nSubClasses := sub size. |
|
592 |
||
593 |
aClass isMeta ifTrue:[ |
|
594 |
className := aClass theNonMetaclass name. |
|
595 |
subNames := sub collect:[:c | c theNonMetaclass name]. |
|
596 |
nSubClasses == 0 ifTrue:[ |
|
597 |
shortText ifTrue:[ |
|
598 |
^ selfString , ' - the ''' , className , '''-class.' |
|
599 |
]. |
|
600 |
^ selfString , 'refers to the object which received the message. |
|
601 |
||
602 |
In this case, it will be the ' , className , '-class itself.' |
|
603 |
]. |
|
604 |
||
605 |
shortText ifTrue:[ |
|
606 |
nSubClasses == 1 ifTrue:[ |
|
607 |
^ selfString , ' - the ''' , className , '''- or ''' , subNames first , '''-class.' |
|
608 |
]. |
|
609 |
^ selfString , ' - the ''' , className , '''-class or one of its subclasses.' |
|
610 |
]. |
|
611 |
nSubClasses <= 5 ifTrue:[ |
|
612 |
^ selfString , ' refers to the object which received the message. |
|
613 |
||
614 |
In this case, it will be the ' , className , '-class |
|
615 |
or one of its subclasses: |
|
616 |
||
617 |
' , subNames asStringCollection asString |
|
618 |
]. |
|
619 |
||
620 |
^ selfString , ' refers to the object which received the message. |
|
621 |
||
622 |
In this case, it will be the ' , className , '-class |
|
623 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
624 |
]. |
|
625 |
||
1256 | 626 |
subNames := aClass allSubclasses collect:[:c | c theNonMetaclass name]. |
1244 | 627 |
className := aClass name. |
628 |
nSubClasses == 0 ifTrue:[ |
|
1183 | 629 |
shortText ifTrue:[ |
1244 | 630 |
^ selfString , ' - an instance of ''' , className , '''.' |
1183 | 631 |
]. |
1198 | 632 |
^ selfString , 'refers to the object which received the message. |
6 | 633 |
|
1244 | 634 |
In this case, it will be an instance of ' , className , '.' |
6 | 635 |
]. |
636 |
||
1183 | 637 |
shortText ifTrue:[ |
1244 | 638 |
nSubClasses == 1 ifTrue:[ |
1256 | 639 |
^ selfString , ' - an instance of ''' , className , ''' or ''' , subNames first , '''.' |
1185 | 640 |
]. |
1244 | 641 |
^ selfString , ' - an instance of ''' , className , ''' or one of its subclasses.' |
1183 | 642 |
]. |
1244 | 643 |
nSubClasses <= 5 ifTrue:[ |
1198 | 644 |
^ selfString , ' refers to the object which received the message. |
6 | 645 |
|
1244 | 646 |
In this case, it will be an instance of ' , className , ' |
6 | 647 |
or one of its subclasses: |
648 |
||
1256 | 649 |
' , subNames asStringCollection asString |
6 | 650 |
]. |
651 |
||
1198 | 652 |
^ selfString , ' refers to the object which received the message. |
6 | 653 |
|
1244 | 654 |
In this case, it will be an instance of ' , className , ' |
655 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
6 | 656 |
! |
657 |
||
1188 | 658 |
explainSuperIn:aClass short:shortText |
1244 | 659 |
|sub superName| |
660 |
||
661 |
superName := aClass superclass name. |
|
1188 | 662 |
|
663 |
"/ sub := aClass allSubclasses collect:[:c | c name]. |
|
664 |
"/ sub size == 0 ifTrue:[ |
|
665 |
"/ shortText ifTrue:[ |
|
666 |
"/ ^ '''super'' - an instance of ''' , aClass name , '''; message lookup starts in ' , aClass superclass name , '.' |
|
667 |
"/ ]. |
|
668 |
"/ ]. |
|
669 |
||
670 |
shortText ifTrue:[ |
|
1244 | 671 |
^ '''super'' - message lookup starts in ' , superName , '.' |
1188 | 672 |
]. |
673 |
||
6 | 674 |
^ 'like self, super refers to the object which received the message. |
675 |
||
676 |
However, when sending a message to super the search for methods |
|
1244 | 677 |
implementing this message will start in the superclass (' , superName , ') |
84 | 678 |
instead of the receivers class (' , aClass name , ' or subclass). |
49 | 679 |
Thus, using super, a redefined method can call the original method in its superclass.' |
6 | 680 |
! |
2 | 681 |
|
49 | 682 |
explainSyntax:string |
683 |
"try syntax ...; return explanation or nil" |
|
684 |
||
1183 | 685 |
^ self explainSyntax:string short:false |
686 |
! |
|
687 |
||
688 |
explainSyntax:string short:shortText |
|
689 |
"try syntax ...; return explanation or nil" |
|
690 |
||
49 | 691 |
((string = ':=') or:[string = '_']) ifTrue:[ |
1183 | 692 |
shortText ifTrue:[ |
693 |
^ 'Assign to variable on the left side.'. |
|
694 |
]. |
|
695 |
||
796 | 696 |
^ '<variable> := <expression> |
49 | 697 |
|
834 | 698 |
'':='' and ''_'' (which is left-arrow in some fonts) mean assignment. |
49 | 699 |
The variable is bound to (i.e. points to) the value of <expression>.' |
700 |
]. |
|
701 |
||
702 |
(string = '^') ifTrue:[ |
|
1183 | 703 |
shortText ifTrue:[ |
704 |
^ 'Return value from method.'. |
|
705 |
]. |
|
796 | 706 |
^ '^ <expression> |
49 | 707 |
|
834 | 708 |
returns the value of <expression> as value from the method. |
49 | 709 |
A return from within a block exits the method where the block is defined.' |
710 |
]. |
|
711 |
||
712 |
(string = ';') ifTrue:[ |
|
1183 | 713 |
shortText ifTrue:[ |
714 |
^ 'Cascade expression.'. |
|
715 |
]. |
|
796 | 716 |
^ '<expression> ; selector1 ; .... ; selectorN |
49 | 717 |
|
718 |
a cascade expression; evaluate expression, and send messages |
|
719 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
720 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
721 |
]. |
|
722 |
||
723 |
(string = '|') ifTrue:[ |
|
1183 | 724 |
shortText ifTrue:[ |
725 |
^ ''. |
|
726 |
]. |
|
796 | 727 |
^ '| locals | or: [:arg | statements] |
49 | 728 |
|
834 | 729 |
''|'' is used to mark a local variable declaration or separates arguments |
49 | 730 |
from the statements in a block. Notice, that in a block-argument declaration |
731 |
these must be prefixed by a colon character. |
|
834 | 732 |
''|'' is also a selector understood by Booleans.' |
49 | 733 |
]. |
734 |
||
735 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
|
1183 | 736 |
shortText ifTrue:[ |
737 |
^ ''. |
|
738 |
]. |
|
796 | 739 |
^ '(<expression>) |
49 | 740 |
|
741 |
expression grouping.' |
|
742 |
]. |
|
743 |
||
744 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
1183 | 745 |
shortText ifTrue:[ |
746 |
^ ''. |
|
747 |
]. |
|
834 | 748 |
^ '[:arg1 .. :argN | statements] |
49 | 749 |
|
750 |
defines a block. |
|
751 |
Blocks represent pieces of executable code. Definition of a block does |
|
752 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
753 |
message. |
|
754 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
755 |
collections (i.e. do:[...]).' |
|
756 |
]. |
|
757 |
||
758 |
(string = ':') ifTrue:[ |
|
1183 | 759 |
shortText ifTrue:[ |
760 |
^ ''. |
|
761 |
]. |
|
796 | 762 |
^ 'colons have different meaning depending on context: |
49 | 763 |
|
764 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
765 |
||
766 |
#at:put: a constant keyword symbol |
|
767 |
||
768 |
rec at:index put:value sends the #at:put: message to rec, |
|
796 | 769 |
passing index and value as arguments. |
49 | 770 |
|
771 |
2) within block-argument declarations as in: |
|
772 |
||
773 |
[:arg1 :arg2 | statements] |
|
834 | 774 |
|
775 |
3) within an identifier, they separate the nameSpace part from |
|
776 |
the name part; as in: |
|
777 |
||
778 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
779 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 780 |
' |
781 |
]. |
|
782 |
||
783 |
(string = '.') ifTrue:[ |
|
796 | 784 |
^ 'statement. "<- period here" |
49 | 785 |
statement |
786 |
||
787 |
within a method or block, individual statements are separated by periods. |
|
788 |
' |
|
789 |
]. |
|
790 |
||
791 |
(string startsWith:'#' ) ifTrue:[ |
|
796 | 792 |
(string startsWith:'#(' ) ifTrue:[ |
1183 | 793 |
shortText ifTrue:[ |
794 |
^ 'Array Literal.'. |
|
795 |
]. |
|
796 | 796 |
^ 'is a constant Array. |
49 | 797 |
|
798 |
The elements of a constant Array must be Number-constants, nil, true or false. |
|
799 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
|
800 |
constant-Array elements).' |
|
796 | 801 |
]. |
49 | 802 |
|
796 | 803 |
(string startsWith:'#[') ifTrue:[ |
1183 | 804 |
shortText ifTrue:[ |
805 |
^ 'ByteArray Literal.'. |
|
806 |
]. |
|
796 | 807 |
^ 'is a constant ByteArray. |
49 | 808 |
|
809 |
The elements of a constant ByteArray must be Integer constants in the range |
|
810 |
0 .. 255. |
|
811 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
|
796 | 812 |
]. |
49 | 813 |
|
796 | 814 |
(string startsWith:'#''') ifTrue:[ |
1183 | 815 |
shortText ifTrue:[ |
816 |
^ 'Symbol Literal.'. |
|
817 |
]. |
|
796 | 818 |
^ 'is a constant symbol containing non-alphanumeric characters. |
49 | 819 |
|
820 |
Symbols are unique strings, meaning that there exists |
|
821 |
exactly one instance of a given symbol. Therefore symbols can |
|
822 |
be compared using == (identity compare) in addition to = (contents compare). |
|
823 |
Beside this, Symbols behave mostly like Strings. |
|
824 |
||
825 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
|
796 | 826 |
]. |
49 | 827 |
|
1232 | 828 |
shortText ifTrue:[ |
829 |
^ 'Symbol Literal.'. |
|
830 |
]. |
|
796 | 831 |
^ 'is a symbol. |
49 | 832 |
|
833 |
Symbols are unique strings, meaning that there exists |
|
834 |
exactly one instance of a given symbol. Therefore symbols can |
|
835 |
be compared using == (identity compare) in addition to = (contents compare). |
|
836 |
Beside this, Symbols behave mostly like Strings.' |
|
837 |
]. |
|
838 |
||
839 |
"/ is it a symbol without hash-character ? |
|
840 |
"/ |
|
796 | 841 |
"/ string knownAsSymbol ifTrue:[ |
842 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
843 |
"/ |
|
844 |
"/Symbols are unique strings, meaning that there exists |
|
845 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
846 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
847 |
"/Beside this, Symbols behave mostly like Strings.' |
|
848 |
"/ ]. |
|
49 | 849 |
|
850 |
^ nil |
|
796 | 851 |
|
852 |
"Modified: / 31.10.1998 / 14:28:58 / cg" |
|
141 | 853 |
! ! |
49 | 854 |
|
396 | 855 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
856 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
857 |
version |
1289 | 858 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.53 2002-07-24 10:17:38 cg Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
859 |
! ! |