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