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