author | Claus Gittinger <cg@exept.de> |
Sun, 29 Jan 2017 12:55:36 +0100 | |
changeset 4103 | 2536fe3291dd |
parent 3816 | cfa6ac81379f |
child 3835 | 087c6f2c4765 |
child 4113 | 2542528ec54a |
permissions | -rw-r--r-- |
662 | 1 |
" |
2 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
1110 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
3560 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
2373 | 16 |
AbstractSyntaxHighlighter subclass:#SyntaxHighlighter |
17 |
instanceVariableNames:'currentSuperclasses currentSubclasses |
|
18 |
cachedLocalIdentifierEmphasis cachedLocalIdentifierColor |
|
19 |
cachedStringEmphasis cachedStringColor' |
|
662 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'System-Compiler' |
|
23 |
! |
|
24 |
||
25 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
||
40 |
||
681 | 41 |
! |
42 |
||
43 |
documentation |
|
44 |
" |
|
45 |
colors a method. |
|
46 |
" |
|
47 |
||
48 |
||
662 | 49 |
! ! |
50 |
||
2892 | 51 |
!SyntaxHighlighter class methodsFor:'constants'! |
52 |
||
53 |
codeAspectClassDefinition |
|
54 |
^ #classDefinition |
|
55 |
||
56 |
"Created: / 27-07-2012 / 22:17:24 / cg" |
|
57 |
! |
|
58 |
||
59 |
codeAspectExpression |
|
60 |
^ #expression |
|
61 |
||
62 |
"Created: / 27-07-2012 / 22:01:26 / cg" |
|
63 |
! |
|
64 |
||
65 |
codeAspectMethod |
|
66 |
^ #method |
|
67 |
||
68 |
"Created: / 27-07-2012 / 22:01:42 / cg" |
|
69 |
! ! |
|
70 |
||
662 | 71 |
!SyntaxHighlighter class methodsFor:'highlighting'! |
72 |
||
1527 | 73 |
formatClassDefinition:aString in:aClass |
74 |
"format (recolor) a class definition expression in a given class. |
|
75 |
Return the text containing font changes and color information." |
|
76 |
||
77 |
^ self formatExpression:aString in:aClass |
|
78 |
! |
|
79 |
||
662 | 80 |
formatMethod:aString in:aClass |
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
81 |
"format (recolor) a method in a given class. |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
82 |
Return the text containing font changes and color information." |
662 | 83 |
|
1550 | 84 |
^ self formatMethod:aString in:aClass using:nil |
85 |
||
86 |
" |
|
87 |
self |
|
88 |
formatMethod:'foo |
|
89 |
^ self bar:''hello''. |
|
90 |
||
91 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
92 |
' |
|
93 |
in:UndefinedObject |
|
94 |
" |
|
95 |
||
96 |
"Modified: / 23.10.1998 / 22:48:45 / cg" |
|
97 |
! |
|
98 |
||
99 |
formatMethod:aString in:aClass using:preferencesOrNil |
|
100 |
"format (recolor) a method in a given class. |
|
101 |
Return the text containing font changes and color information." |
|
102 |
||
3598 | 103 |
"/ cg: I smell a wumpus: I don't think, all of this must be redefined - most is already there in the superclass. |
104 |
||
105 |
|highlighter tree newText| |
|
662 | 106 |
|
107 |
aString isNil ifTrue:[^ nil]. |
|
108 |
||
1110 | 109 |
Error handle:[:ex | |
3598 | 110 |
"/ Transcript showCR:ex description. |
3068 | 111 |
(ParseError handles:ex) ifFalse:[ |
3598 | 112 |
ex creator isHandled ifTrue:[ |
113 |
"/ Transcript showCR:'handled'. |
|
114 |
ex reject. |
|
115 |
]. |
|
2087
42c0f2fe415d
Do not write Warning messages about parse errors
Stefan Vogel <sv@exept.de>
parents:
2070
diff
changeset
|
116 |
"Parse error may happen when re-formatting incomplete code while editing" |
2807
48955b6f8874
changed: #formatMethod:in:using:
Claus Gittinger <cg@exept.de>
parents:
2460
diff
changeset
|
117 |
"/ ('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR. |
2087
42c0f2fe415d
Do not write Warning messages about parse errors
Stefan Vogel <sv@exept.de>
parents:
2070
diff
changeset
|
118 |
"/ ex suspendedContext fullPrintAll. |
42c0f2fe415d
Do not write Warning messages about parse errors
Stefan Vogel <sv@exept.de>
parents:
2070
diff
changeset
|
119 |
]. |
3598 | 120 |
highlighter notNil ifTrue:[ |
121 |
^ self colorize:(newText ? aString) forErrorAtPosition:highlighter sourceStream position withOriginal:aString |
|
122 |
]. |
|
689 | 123 |
^ aString |
124 |
] do:[ |
|
3598 | 125 |
|sourceString| |
126 |
||
127 |
sourceString := aString string. |
|
128 |
newText := sourceString asUnicode16String asText. |
|
129 |
"/ use an array here (instead of the RunArray) - this can be changed much faster using #at:put: |
|
130 |
newText emphasisCollection:(Array new:sourceString size). |
|
131 |
||
132 |
highlighter := self for:(ReadStream on:sourceString) in:aClass. |
|
1550 | 133 |
preferencesOrNil notNil ifTrue:[highlighter preferences:preferencesOrNil]. |
1857 | 134 |
"/ highlighter ignoreErrors:true. |
1550 | 135 |
highlighter ignoreWarnings:true. |
3598 | 136 |
highlighter sourceText:newText. |
662 | 137 |
|
1550 | 138 |
tree := highlighter parseMethod. |
3598 | 139 |
newText := highlighter sourceText. "/ might have changed identity |
689 | 140 |
"/ now, convert the emphasis-array to a runArray |
3598 | 141 |
newText emphasisCollection:(newText emphasis asRunArray). |
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
142 |
|
689 | 143 |
tree == #Error ifTrue:[ |
3598 | 144 |
^ self colorize:newText forErrorAtPosition:highlighter sourceStream position withOriginal:aString. |
145 |
]. |
|
146 |
^ newText |
|
147 |
] |
|
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
148 |
|
662 | 149 |
" |
150 |
self |
|
151 |
formatMethod:'foo |
|
152 |
^ self bar:''hello''. |
|
153 |
||
154 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
155 |
' |
|
156 |
in:UndefinedObject |
|
157 |
" |
|
158 |
||
2807
48955b6f8874
changed: #formatMethod:in:using:
Claus Gittinger <cg@exept.de>
parents:
2460
diff
changeset
|
159 |
"Modified: / 04-02-2012 / 11:53:16 / cg" |
662 | 160 |
! ! |
161 |
||
162 |
!SyntaxHighlighter methodsFor:'initialization'! |
|
163 |
||
164 |
initialize |
|
165 |
super initialize. |
|
166 |
||
990
cd1aa00086fd
dont care to fold constants during syntaxHighlight
Claus Gittinger <cg@exept.de>
parents:
987
diff
changeset
|
167 |
foldConstants := false. |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1553
diff
changeset
|
168 |
"/ parserFlags allowDollarInIdentifier:true. |
990
cd1aa00086fd
dont care to fold constants during syntaxHighlight
Claus Gittinger <cg@exept.de>
parents:
987
diff
changeset
|
169 |
|
1526 | 170 |
preferences := UserPreferences current. |
868 | 171 |
|
1526 | 172 |
fullSelectorCheck := preferences fullSelectorCheck. |
662 | 173 |
|
174 |
"Created: / 31.3.1998 / 15:12:55 / cg" |
|
838 | 175 |
"Modified: / 5.1.1980 / 00:44:03 / cg" |
662 | 176 |
! ! |
177 |
||
178 |
!SyntaxHighlighter methodsFor:'syntax detection'! |
|
179 |
||
180 |
markArgumentIdentifierFrom:pos1 to:pos2 |
|
181 |
self |
|
182 |
markFrom:pos1 to:pos2 |
|
1553 | 183 |
withEmphasis:(preferences argumentIdentifierEmphasis) |
184 |
color:(preferences argumentIdentifierColor) |
|
662 | 185 |
|
186 |
"Modified: / 31.3.1998 / 18:01:27 / cg" |
|
187 |
! |
|
188 |
||
2811 | 189 |
markAssignedClassVariableIdentifierFrom:pos1 to:pos2 |
190 |
self |
|
191 |
markFrom:pos1 to:pos2 |
|
3560 | 192 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences classVariableIdentifierEmphasis) |
193 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences classVariableIdentifierColor) |
|
2811 | 194 |
backgroundColor:(preferences sideEffectAssignmentBackgroundColor) |
195 |
||
196 |
"Created: / 13-02-2012 / 11:49:59 / cg" |
|
197 |
! |
|
198 |
||
199 |
markAssignedGlobalIdentifierFrom:pos1 to:pos2 |
|
200 |
self |
|
201 |
markFrom:pos1 to:pos2 |
|
3560 | 202 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences globalIdentifierEmphasis) |
203 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences globalIdentifierColor) |
|
2811 | 204 |
backgroundColor:(preferences sideEffectAssignmentBackgroundColor) |
205 |
||
206 |
"Modified: / 31-03-1998 / 18:02:14 / cg" |
|
207 |
"Created: / 13-02-2012 / 11:44:33 / cg" |
|
208 |
! |
|
209 |
||
2997 | 210 |
markAssignedIdentifierFrom:pos1 to:pos2 |
211 |
"any other identifier (PrivateClass, Workspace, Doit, etc.)" |
|
212 |
||
213 |
self markAssignedGlobalIdentifierFrom:pos1 to:pos2 |
|
214 |
! |
|
215 |
||
2811 | 216 |
markAssignedInstVarIdentifierFrom:pos1 to:pos2 |
217 |
self |
|
218 |
markFrom:pos1 to:pos2 |
|
3560 | 219 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences instVarIdentifierEmphasis) |
220 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences instVarIdentifierColor) |
|
2811 | 221 |
backgroundColor:(preferences sideEffectAssignmentBackgroundColor) |
222 |
||
223 |
"Created: / 13-02-2012 / 11:50:19 / cg" |
|
224 |
! |
|
225 |
||
226 |
markAssignedPoolVariableIdentifierFrom:pos1 to:pos2 |
|
227 |
self |
|
228 |
markFrom:pos1 to:pos2 |
|
3560 | 229 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences poolVariableIdentifierEmphasis) |
230 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences poolVariableIdentifierColor) |
|
2811 | 231 |
backgroundColor:(preferences sideEffectAssignmentBackgroundColor) |
232 |
||
233 |
"Created: / 13-02-2012 / 11:49:14 / cg" |
|
234 |
! |
|
235 |
||
236 |
markAssignedVariable:v from:pos to:endPos |
|
237 |
"support for syntaxColoring" |
|
238 |
||
239 |
|type| |
|
240 |
||
241 |
type := v type. |
|
242 |
(type == #BlockArg |
|
243 |
or:[ type == #MethodArg |
|
244 |
or:[ type == #BlockVariable |
|
245 |
or:[ type == #MethodVariable]]]) ifTrue:[ |
|
3187 | 246 |
self markVariable:v from:pos to:endPos assigned:true. |
2811 | 247 |
^ self |
248 |
]. |
|
249 |
(type == #GlobalVariable) ifTrue:[ |
|
250 |
self markAssignedGlobalIdentifierFrom:pos to:endPos. |
|
251 |
^ self |
|
252 |
]. |
|
253 |
(type == #PoolVariable) ifTrue:[ |
|
254 |
self markAssignedPoolVariableIdentifierFrom:pos to:endPos. |
|
255 |
^ self |
|
256 |
]. |
|
257 |
(type == #ClassVariable) ifTrue:[ |
|
258 |
self markAssignedClassVariableIdentifierFrom:pos to:endPos. |
|
259 |
^ self |
|
260 |
]. |
|
261 |
(type == #InstanceVariable) ifTrue:[ |
|
262 |
self markAssignedInstVarIdentifierFrom:pos to:endPos. |
|
263 |
^ self |
|
264 |
]. |
|
265 |
||
266 |
self markAssignedIdentifierFrom:pos to:endPos. |
|
267 |
||
268 |
"Created: / 13-02-2012 / 11:42:23 / cg" |
|
269 |
! |
|
270 |
||
884 | 271 |
markBadIdentifierFrom:pos1 to:pos2 |
272 |
self |
|
273 |
markFrom:pos1 to:pos2 |
|
1553 | 274 |
withEmphasis:(preferences badIdentifierEmphasis) |
275 |
color:(preferences badIdentifierColor) |
|
884 | 276 |
! |
277 |
||
2055 | 278 |
markBlockFrom:pos1 to:pos2 |
2228 | 279 |
"an experiment (which does not look too good, after all): |
280 |
the deeper the nesting of the block, the darker the background color." |
|
281 |
||
2055 | 282 |
"/ |level color| |
283 |
"/ |
|
284 |
"/ level := currentBlock isNil ifTrue:[1] ifFalse:[currentBlock nestingLevel+1]. |
|
2228 | 285 |
"/ level > 5 ifTrue:[ |
286 |
"/ color := Color yellow darkened. |
|
287 |
"/ ] ifFalse:[ |
|
288 |
"/ color := { |
|
289 |
"/ Color yellow lightened lightened. |
|
290 |
"/ Color yellow lightened . |
|
291 |
"/ Color yellow . |
|
292 |
"/ Color yellow slightlyDarkened . |
|
293 |
"/ Color yellow darkened . |
|
294 |
"/ } at:level. |
|
295 |
"/ ]. |
|
2055 | 296 |
"/ self |
297 |
"/ markFrom:pos1 to:pos2 |
|
2228 | 298 |
"/ withAddedEmphasis:(#backgroundColor->color). |
2055 | 299 |
! |
300 |
||
662 | 301 |
markBooleanConstantFrom:pos1 to:pos2 |
302 |
self |
|
303 |
markFrom:pos1 to:pos2 |
|
1553 | 304 |
withEmphasis:(preferences booleanConstantEmphasis) |
305 |
color:(preferences booleanConstantColor) |
|
662 | 306 |
|
307 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
665 | 308 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
662 | 309 |
! |
310 |
||
673 | 311 |
markBracketAt:pos |
2070 | 312 |
|level colors clr em| |
313 |
||
314 |
preferences emphasizeParenthesisLevel ifFalse:[ |
|
315 |
self |
|
316 |
markFrom:pos to:pos |
|
317 |
withEmphasis:(preferences bracketEmphasis) |
|
318 |
color:(preferences bracketColor). |
|
319 |
||
320 |
^ self |
|
321 |
]. |
|
322 |
||
323 |
level := currentBlock isNil ifTrue:[1] ifFalse:[currentBlock nestingLevel + 2]. |
|
324 |
(sourceText at:pos) = $] ifTrue:[ |
|
325 |
level := level - 1. |
|
326 |
]. |
|
327 |
||
328 |
colors := Array |
|
329 |
with:(Color black) |
|
330 |
with:(Color blue) |
|
331 |
with:(Color green blendWith:(Color grey:30)) |
|
332 |
with:(Color red blendWith:(Color grey:30)) |
|
333 |
with:(Color yellow darkened). |
|
334 |
||
335 |
clr := colors at:((level-1) \\ colors size + 1). |
|
336 |
em := #normal. |
|
337 |
level > 1 ifTrue:[ |
|
338 |
em := #bold. |
|
339 |
]. |
|
673 | 340 |
self |
341 |
markFrom:pos to:pos |
|
2070 | 342 |
withEmphasis:em |
343 |
color:clr |
|
673 | 344 |
! |
345 |
||
870 | 346 |
markClassVariableIdentifierFrom:pos1 to:pos2 |
347 |
self |
|
348 |
markFrom:pos1 to:pos2 |
|
1553 | 349 |
withEmphasis:(preferences classVariableIdentifierEmphasis) |
350 |
color:(preferences classVariableIdentifierColor) |
|
870 | 351 |
|
352 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
353 |
! |
|
354 |
||
662 | 355 |
markCommentFrom:pos1 to:pos2 |
356 |
self |
|
357 |
markFrom:pos1 to:pos2 |
|
1553 | 358 |
withEmphasis:(preferences commentEmphasis) |
359 |
color:(preferences commentColor) |
|
3353 | 360 |
font:(preferences commentFont) |
662 | 361 |
|
1550 | 362 |
" |
363 |
UserPreferences current commentEmphasis |
|
364 |
" |
|
365 |
"Modified: / 31.3.1998 / 18:01:55 / cg" |
|
662 | 366 |
! |
367 |
||
368 |
markConstantFrom:pos1 to:pos2 |
|
369 |
self |
|
370 |
markFrom:pos1 to:pos2 |
|
1553 | 371 |
withEmphasis:(preferences constantEmphasis) |
372 |
color:(preferences constantColor) |
|
662 | 373 |
|
374 |
"Modified: / 31.3.1998 / 18:01:44 / cg" |
|
375 |
"Created: / 31.3.1998 / 18:09:22 / cg" |
|
376 |
! |
|
377 |
||
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
378 |
markGlobalClassIdentifierFrom:pos1 to:pos2 |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
379 |
self |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
380 |
markFrom:pos1 to:pos2 |
1553 | 381 |
withEmphasis:(preferences globalClassIdentifierEmphasis) |
382 |
color:(preferences globalClassIdentifierColor) |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
383 |
|
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
384 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
385 |
"Created: / 4.3.1999 / 12:53:02 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
386 |
! |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
387 |
|
662 | 388 |
markGlobalIdentifierFrom:pos1 to:pos2 |
389 |
self |
|
390 |
markFrom:pos1 to:pos2 |
|
1553 | 391 |
withEmphasis:(preferences globalIdentifierEmphasis) |
392 |
color:(preferences globalIdentifierColor) |
|
662 | 393 |
|
394 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
395 |
! |
|
396 |
||
397 |
markHereFrom:pos1 to:pos2 |
|
398 |
self |
|
399 |
markFrom:pos1 to:pos2 |
|
1553 | 400 |
withEmphasis:(preferences hereEmphasis) |
401 |
color:(preferences hereColor) |
|
662 | 402 |
|
403 |
"Modified: / 31.3.1998 / 18:02:25 / cg" |
|
404 |
! |
|
405 |
||
406 |
markIdentifierFrom:pos1 to:pos2 |
|
407 |
self |
|
408 |
markFrom:pos1 to:pos2 |
|
1553 | 409 |
withEmphasis:(preferences identifierEmphasis) |
410 |
color:(preferences identifierColor) |
|
662 | 411 |
|
412 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
413 |
"Created: / 31.3.1998 / 18:04:56 / cg" |
|
414 |
! |
|
415 |
||
686 | 416 |
markInstVarIdentifierFrom:pos1 to:pos2 |
417 |
self |
|
418 |
markFrom:pos1 to:pos2 |
|
1553 | 419 |
withEmphasis:(preferences instVarIdentifierEmphasis) |
420 |
color:(preferences instVarIdentifierColor) |
|
686 | 421 |
|
422 |
"Created: / 16.4.1998 / 18:35:40 / cg" |
|
423 |
"Modified: / 16.4.1998 / 18:37:30 / cg" |
|
424 |
! |
|
425 |
||
662 | 426 |
markLocalIdentifierFrom:pos1 to:pos2 |
1802 | 427 |
cachedLocalIdentifierEmphasis isNil ifTrue:[ |
428 |
cachedLocalIdentifierEmphasis := preferences localIdentifierEmphasis. |
|
429 |
cachedLocalIdentifierColor := preferences localIdentifierColor. |
|
430 |
]. |
|
662 | 431 |
self |
432 |
markFrom:pos1 to:pos2 |
|
1802 | 433 |
withEmphasis:cachedLocalIdentifierEmphasis |
434 |
color:cachedLocalIdentifierColor |
|
662 | 435 |
|
436 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
437 |
! |
|
438 |
||
439 |
markMethodSelectorFrom:pos1 to:pos2 |
|
440 |
self |
|
441 |
markFrom:pos1 to:pos2 |
|
1553 | 442 |
withEmphasis:(preferences methodSelectorEmphasis) |
443 |
color:(preferences methodSelectorColor) |
|
662 | 444 |
|
445 |
"Modified: / 31.3.1998 / 18:02:52 / cg" |
|
446 |
! |
|
447 |
||
1684 | 448 |
markNumberConstantFrom:pos1 to:pos2 |
449 |
self |
|
450 |
markFrom:pos1 to:pos2 |
|
451 |
withEmphasis:(preferences numberConstantEmphasis) |
|
452 |
color:(preferences numberConstantColor) |
|
453 |
||
454 |
"Modified: / 31.3.1998 / 18:01:44 / cg" |
|
455 |
"Created: / 31.3.1998 / 18:09:22 / cg" |
|
456 |
! |
|
457 |
||
1640
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
458 |
markParenthesisAt:pos |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
459 |
|colors clr em| |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
460 |
|
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
461 |
preferences emphasizeParenthesisLevel ifFalse:[^ self]. |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
462 |
|
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
463 |
colors := Array |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
464 |
with:(Color black) |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
465 |
with:(Color blue) |
1757 | 466 |
with:(Color green blendWith:(Color grey:30)) |
467 |
with:(Color red blendWith:(Color grey:30)) |
|
1640
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
468 |
with:(Color yellow darkened). |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
469 |
|
1757 | 470 |
clr := colors at:((parenthesisLevel-1) \\ colors size + 1). |
1640
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
471 |
em := #normal. |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
472 |
parenthesisLevel > 1 ifTrue:[ |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
473 |
em := #bold. |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
474 |
]. |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
475 |
self |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
476 |
markFrom:pos to:pos |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
477 |
withEmphasis:em |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
478 |
color:clr |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
479 |
! |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
480 |
|
1553 | 481 |
markPoolVariableIdentifierFrom:pos1 to:pos2 |
482 |
self |
|
483 |
markFrom:pos1 to:pos2 |
|
484 |
withEmphasis:(preferences poolVariableIdentifierEmphasis) |
|
485 |
color:(preferences poolVariableIdentifierColor) |
|
486 |
! |
|
487 |
||
838 | 488 |
markReturnAt:pos |
3598 | 489 |
"/ sourceText := (sourceText copyTo:pos-1),(Character value:16r21e7),(sourceText copyFrom:pos+1). |
838 | 490 |
self |
491 |
markFrom:pos to:pos |
|
1553 | 492 |
withEmphasis:(preferences returnEmphasis) |
493 |
color:(preferences returnColor) |
|
838 | 494 |
|
495 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
|
496 |
"Created: / 5.1.1980 / 00:44:27 / cg" |
|
497 |
! |
|
498 |
||
863 | 499 |
markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode |
1498
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
500 |
|fg selectorSymbol check ok rec em| |
863 | 501 |
|
502 |
"/ uncommenting the code below |
|
503 |
"/ will suppress highlighting of common selectors ... |
|
504 |
"/ |
|
505 |
"/ (#( |
|
506 |
"/ 'ifTrue:' |
|
507 |
"/ 'ifFalse:' |
|
508 |
"/ 'not' |
|
509 |
"/ 'and:' |
|
510 |
"/ 'or:' |
|
511 |
"/ '=' |
|
512 |
"/ '==' |
|
513 |
"/ '~=' |
|
514 |
"/ '~~' |
|
515 |
"/ ) includes:sel) ifTrue:[ |
|
516 |
"/ ^ self |
|
517 |
"/ ]. |
|
518 |
||
1526 | 519 |
fg := preferences selectorColor. |
520 |
em := preferences selectorEmphasis. |
|
1498
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
521 |
selectorSymbol := selectorString asSymbolIfInterned. |
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
522 |
selectorSymbol isNil ifTrue:[ |
1905 | 523 |
em := preferences unimplementedSelectorEmphasis. |
524 |
fg := preferences unimplementedSelectorColor. |
|
1498
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
525 |
] ifFalse:[ |
1905 | 526 |
ok := true. |
527 |
||
863 | 528 |
fullSelectorCheck == true ifTrue:[ |
529 |
||
1498
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
530 |
check := [:cls | (cls includesSelector:selectorSymbol) |
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
531 |
or:[cls class includesSelector:selectorSymbol]]. |
863 | 532 |
|
533 |
ok := false. |
|
534 |
||
535 |
"/ limit search if possible |
|
536 |
(classToCompileFor notNil |
|
537 |
and:[aReceiverNode isSelf or:[aReceiverNode isSuper]]) ifTrue:[ |
|
538 |
currentSuperclasses isNil ifTrue:[ |
|
539 |
currentSuperclasses := classToCompileFor withAllSuperclasses. |
|
540 |
]. |
|
541 |
ok := currentSuperclasses contains:check. |
|
542 |
(ok not and:[aReceiverNode isSelf]) ifTrue:[ |
|
543 |
currentSubclasses isNil ifTrue:[ |
|
544 |
currentSubclasses := classToCompileFor allSubclasses. |
|
545 |
]. |
|
546 |
ok := currentSubclasses contains:check. |
|
547 |
]. |
|
548 |
] ifFalse:[ |
|
3816 | 549 |
aReceiverNode isLiteral ifTrue:[ |
863 | 550 |
ok := aReceiverNode evaluate class withAllSuperclasses contains:check. |
551 |
] ifFalse:[ |
|
552 |
(aReceiverNode isGlobal |
|
553 |
and:[(rec := aReceiverNode evaluate) isBehavior]) ifTrue:[ |
|
554 |
ok := rec class withAllSuperclasses contains:check. |
|
555 |
] ifFalse:[ |
|
556 |
ok := Smalltalk allClasses contains:check |
|
557 |
] |
|
558 |
] |
|
559 |
]. |
|
1905 | 560 |
]. |
3232 | 561 |
|
1905 | 562 |
ok ifFalse:[ |
563 |
em := preferences unimplementedSelectorEmphasis. |
|
564 |
fg := preferences unimplementedSelectorColor. |
|
565 |
] ifTrue:[ |
|
3343 | 566 |
(self class isControlFlowSelector:selectorSymbol) ifTrue:[ |
1905 | 567 |
em := preferences controlFlowSelectorEmphasis. |
2816
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
568 |
fg := preferences controlFlowSelectorColor |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
569 |
] ifFalse:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
570 |
(self collectionEnumerationSelectors includesIdentical:selectorSymbol) ifTrue:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
571 |
em := preferences collectionEnumerationSelectorEmphasis. |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
572 |
fg := preferences collectionEnumerationSelectorColor |
3229 | 573 |
] ifFalse:[ |
574 |
(self debugSelectors includesIdentical:selectorSymbol) ifTrue:[ |
|
575 |
em := preferences debugSelectorEmphasis. |
|
576 |
fg := preferences debugSelectorColor |
|
577 |
] ifFalse:[ |
|
578 |
(self errorRaisingSelectors includesIdentical:selectorSymbol) ifTrue:[ |
|
579 |
em := preferences errorRaisingSelectorEmphasis. |
|
580 |
fg := preferences errorRaisingSelectorColor |
|
581 |
]. |
|
582 |
]. |
|
2816
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
583 |
]. |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
584 |
]. |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
585 |
em isNil ifTrue:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
586 |
em := preferences selectorEmphasis |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
587 |
]. |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
588 |
fg isNil ifTrue:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
589 |
fg := preferences selectorColor |
1905 | 590 |
]. |
591 |
]. |
|
863 | 592 |
]. |
593 |
self |
|
594 |
markFrom:pos1 to:pos2 |
|
1553 | 595 |
withEmphasis:em |
596 |
color:fg |
|
863 | 597 |
|
2816
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
598 |
"Modified: / 14-02-2012 / 16:03:52 / cg" |
863 | 599 |
! |
600 |
||
662 | 601 |
markSelfFrom:pos1 to:pos2 |
602 |
self |
|
603 |
markFrom:pos1 to:pos2 |
|
1553 | 604 |
withEmphasis:(preferences selfEmphasis) |
605 |
color:(preferences selfColor) |
|
662 | 606 |
|
607 |
"Modified: / 31.3.1998 / 18:03:10 / cg" |
|
608 |
! |
|
609 |
||
610 |
markStringFrom:pos1 to:pos2 |
|
1802 | 611 |
cachedStringEmphasis isNil ifTrue:[ |
612 |
cachedStringEmphasis := preferences stringEmphasis. |
|
613 |
cachedStringColor := preferences stringColor. |
|
614 |
]. |
|
662 | 615 |
self |
616 |
markFrom:pos1 to:pos2 |
|
1802 | 617 |
withEmphasis:cachedStringEmphasis |
618 |
color:cachedStringColor |
|
662 | 619 |
|
620 |
"Modified: / 31.3.1998 / 18:03:18 / cg" |
|
621 |
! |
|
622 |
||
623 |
markSuperFrom:pos1 to:pos2 |
|
624 |
self |
|
625 |
markFrom:pos1 to:pos2 |
|
1553 | 626 |
withEmphasis:(preferences superEmphasis) |
627 |
color:(preferences superColor) |
|
662 | 628 |
|
629 |
"Modified: / 31.3.1998 / 18:03:26 / cg" |
|
630 |
! |
|
631 |
||
672 | 632 |
markSymbolFrom:pos1 to:pos2 |
633 |
self |
|
634 |
markFrom:pos1 to:pos2 |
|
1553 | 635 |
withEmphasis:(preferences symbolEmphasis) |
636 |
color:(preferences symbolColor) |
|
672 | 637 |
|
638 |
"Created: / 1.4.1998 / 12:56:47 / cg" |
|
639 |
"Modified: / 1.4.1998 / 12:58:00 / cg" |
|
640 |
! |
|
641 |
||
662 | 642 |
markThisContextFrom:pos1 to:pos2 |
643 |
self |
|
644 |
markFrom:pos1 to:pos2 |
|
1553 | 645 |
withEmphasis:(preferences thisContextEmphasis) |
646 |
color:(preferences thisContextColor) |
|
662 | 647 |
|
648 |
"Modified: / 31.3.1998 / 18:03:36 / cg" |
|
665 | 649 |
! |
650 |
||
651 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
652 |
self |
|
653 |
markFrom:pos1 to:pos2 |
|
1553 | 654 |
withEmphasis:(preferences unknownIdentifierEmphasis) |
655 |
color:(preferences unknownIdentifierColor) |
|
665 | 656 |
|
657 |
"Created: / 31.3.1998 / 19:09:26 / cg" |
|
658 |
"Modified: / 31.3.1998 / 19:10:30 / cg" |
|
686 | 659 |
! |
660 |
||
3187 | 661 |
markVariable:v from:pos to:endPos assigned:assigned |
686 | 662 |
"support for syntaxColoring" |
663 |
||
823 | 664 |
|type globalValue nameSym| |
686 | 665 |
|
666 |
type := v type. |
|
667 |
(type == #BlockArg |
|
668 |
or:[type == #MethodArg]) ifTrue:[ |
|
669 |
self markArgumentIdentifierFrom:pos to:endPos. |
|
670 |
^ self |
|
671 |
]. |
|
672 |
(type == #BlockVariable |
|
673 |
or:[type == #MethodVariable]) ifTrue:[ |
|
674 |
self markLocalIdentifierFrom:pos to:endPos. |
|
675 |
^ self |
|
676 |
]. |
|
677 |
(type == #GlobalVariable) ifTrue:[ |
|
823 | 678 |
nameSym := v name asSymbolIfInterned. |
679 |
nameSym notNil ifTrue:[ |
|
680 |
globalValue := Smalltalk at:nameSym ifAbsent:nil. |
|
681 |
]. |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
682 |
globalValue isBehavior ifTrue:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
683 |
self markGlobalClassIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
684 |
] ifFalse:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
685 |
self markGlobalIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
686 |
]. |
686 | 687 |
^ self |
688 |
]. |
|
1553 | 689 |
(type == #PoolVariable) ifTrue:[ |
690 |
self markPoolVariableIdentifierFrom:pos to:endPos. |
|
691 |
^ self |
|
692 |
]. |
|
870 | 693 |
(type == #ClassVariable) ifTrue:[ |
694 |
self markClassVariableIdentifierFrom:pos to:endPos. |
|
695 |
^ self |
|
696 |
]. |
|
686 | 697 |
(type == #InstanceVariable) ifTrue:[ |
698 |
self markInstVarIdentifierFrom:pos to:endPos. |
|
699 |
^ self |
|
700 |
]. |
|
701 |
||
702 |
self markIdentifierFrom:pos to:endPos. |
|
703 |
||
704 |
"Created: / 16.4.1998 / 18:49:34 / cg" |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
705 |
"Modified: / 4.3.1999 / 12:56:13 / cg" |
662 | 706 |
! ! |
707 |
||
708 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
709 |
||
710 |
version |
|
3816 | 711 |
^ '$Header$' |
2228 | 712 |
! |
713 |
||
714 |
version_CVS |
|
3816 | 715 |
^ '$Header$' |
662 | 716 |
! ! |
2997 | 717 |