author | convert-repo |
Mon, 13 Feb 2017 04:34:40 +0000 | |
changeset 4120 | 7cb0d66f736c |
parent 4113 | 2542528ec54a |
child 4199 | 6004749f33b2 |
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 |
|
4113 | 165 |
<modifier: #super> "must be called if redefined" |
166 |
||
662 | 167 |
super initialize. |
168 |
||
990
cd1aa00086fd
dont care to fold constants during syntaxHighlight
Claus Gittinger <cg@exept.de>
parents:
987
diff
changeset
|
169 |
foldConstants := false. |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1553
diff
changeset
|
170 |
"/ parserFlags allowDollarInIdentifier:true. |
990
cd1aa00086fd
dont care to fold constants during syntaxHighlight
Claus Gittinger <cg@exept.de>
parents:
987
diff
changeset
|
171 |
|
1526 | 172 |
preferences := UserPreferences current. |
868 | 173 |
|
1526 | 174 |
fullSelectorCheck := preferences fullSelectorCheck. |
662 | 175 |
|
4113 | 176 |
"Created: / 31-03-1998 / 15:12:55 / cg" |
177 |
"Modified: / 08-02-2017 / 00:31:32 / cg" |
|
662 | 178 |
! ! |
179 |
||
180 |
!SyntaxHighlighter methodsFor:'syntax detection'! |
|
181 |
||
182 |
markArgumentIdentifierFrom:pos1 to:pos2 |
|
183 |
self |
|
184 |
markFrom:pos1 to:pos2 |
|
1553 | 185 |
withEmphasis:(preferences argumentIdentifierEmphasis) |
186 |
color:(preferences argumentIdentifierColor) |
|
662 | 187 |
|
188 |
"Modified: / 31.3.1998 / 18:01:27 / cg" |
|
189 |
! |
|
190 |
||
2811 | 191 |
markAssignedClassVariableIdentifierFrom:pos1 to:pos2 |
192 |
self |
|
193 |
markFrom:pos1 to:pos2 |
|
3560 | 194 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences classVariableIdentifierEmphasis) |
195 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences classVariableIdentifierColor) |
|
2811 | 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 |
|
3560 | 204 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences globalIdentifierEmphasis) |
205 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences globalIdentifierColor) |
|
2811 | 206 |
backgroundColor:(preferences sideEffectAssignmentBackgroundColor) |
207 |
||
208 |
"Modified: / 31-03-1998 / 18:02:14 / cg" |
|
209 |
"Created: / 13-02-2012 / 11:44:33 / cg" |
|
210 |
! |
|
211 |
||
2997 | 212 |
markAssignedIdentifierFrom:pos1 to:pos2 |
213 |
"any other identifier (PrivateClass, Workspace, Doit, etc.)" |
|
214 |
||
215 |
self markAssignedGlobalIdentifierFrom:pos1 to:pos2 |
|
216 |
! |
|
217 |
||
2811 | 218 |
markAssignedInstVarIdentifierFrom:pos1 to:pos2 |
219 |
self |
|
220 |
markFrom:pos1 to:pos2 |
|
3560 | 221 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences instVarIdentifierEmphasis) |
222 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences instVarIdentifierColor) |
|
2811 | 223 |
backgroundColor:(preferences sideEffectAssignmentBackgroundColor) |
224 |
||
225 |
"Created: / 13-02-2012 / 11:50:19 / cg" |
|
226 |
! |
|
227 |
||
228 |
markAssignedPoolVariableIdentifierFrom:pos1 to:pos2 |
|
229 |
self |
|
230 |
markFrom:pos1 to:pos2 |
|
3560 | 231 |
withEmphasis:(preferences sideEffectAssignmentEmphasis) ifNil:(preferences poolVariableIdentifierEmphasis) |
232 |
color:(preferences sideEffectAssignmentColor) ifNil:(preferences poolVariableIdentifierColor) |
|
2811 | 233 |
backgroundColor:(preferences sideEffectAssignmentBackgroundColor) |
234 |
||
235 |
"Created: / 13-02-2012 / 11:49:14 / cg" |
|
236 |
! |
|
237 |
||
238 |
markAssignedVariable:v from:pos to:endPos |
|
239 |
"support for syntaxColoring" |
|
240 |
||
241 |
|type| |
|
242 |
||
243 |
type := v type. |
|
244 |
(type == #BlockArg |
|
245 |
or:[ type == #MethodArg |
|
246 |
or:[ type == #BlockVariable |
|
247 |
or:[ type == #MethodVariable]]]) ifTrue:[ |
|
3187 | 248 |
self markVariable:v from:pos to:endPos assigned:true. |
2811 | 249 |
^ self |
250 |
]. |
|
251 |
(type == #GlobalVariable) ifTrue:[ |
|
252 |
self markAssignedGlobalIdentifierFrom:pos to:endPos. |
|
253 |
^ self |
|
254 |
]. |
|
255 |
(type == #PoolVariable) ifTrue:[ |
|
256 |
self markAssignedPoolVariableIdentifierFrom:pos to:endPos. |
|
257 |
^ self |
|
258 |
]. |
|
259 |
(type == #ClassVariable) ifTrue:[ |
|
260 |
self markAssignedClassVariableIdentifierFrom:pos to:endPos. |
|
261 |
^ self |
|
262 |
]. |
|
263 |
(type == #InstanceVariable) ifTrue:[ |
|
264 |
self markAssignedInstVarIdentifierFrom:pos to:endPos. |
|
265 |
^ self |
|
266 |
]. |
|
267 |
||
268 |
self markAssignedIdentifierFrom:pos to:endPos. |
|
269 |
||
270 |
"Created: / 13-02-2012 / 11:42:23 / cg" |
|
271 |
! |
|
272 |
||
884 | 273 |
markBadIdentifierFrom:pos1 to:pos2 |
274 |
self |
|
275 |
markFrom:pos1 to:pos2 |
|
1553 | 276 |
withEmphasis:(preferences badIdentifierEmphasis) |
277 |
color:(preferences badIdentifierColor) |
|
884 | 278 |
! |
279 |
||
2055 | 280 |
markBlockFrom:pos1 to:pos2 |
2228 | 281 |
"an experiment (which does not look too good, after all): |
282 |
the deeper the nesting of the block, the darker the background color." |
|
283 |
||
2055 | 284 |
"/ |level color| |
285 |
"/ |
|
286 |
"/ level := currentBlock isNil ifTrue:[1] ifFalse:[currentBlock nestingLevel+1]. |
|
2228 | 287 |
"/ level > 5 ifTrue:[ |
288 |
"/ color := Color yellow darkened. |
|
289 |
"/ ] ifFalse:[ |
|
290 |
"/ color := { |
|
291 |
"/ Color yellow lightened lightened. |
|
292 |
"/ Color yellow lightened . |
|
293 |
"/ Color yellow . |
|
294 |
"/ Color yellow slightlyDarkened . |
|
295 |
"/ Color yellow darkened . |
|
296 |
"/ } at:level. |
|
297 |
"/ ]. |
|
2055 | 298 |
"/ self |
299 |
"/ markFrom:pos1 to:pos2 |
|
2228 | 300 |
"/ withAddedEmphasis:(#backgroundColor->color). |
2055 | 301 |
! |
302 |
||
662 | 303 |
markBooleanConstantFrom:pos1 to:pos2 |
304 |
self |
|
305 |
markFrom:pos1 to:pos2 |
|
1553 | 306 |
withEmphasis:(preferences booleanConstantEmphasis) |
307 |
color:(preferences booleanConstantColor) |
|
662 | 308 |
|
309 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
665 | 310 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
662 | 311 |
! |
312 |
||
673 | 313 |
markBracketAt:pos |
2070 | 314 |
|level colors clr em| |
315 |
||
316 |
preferences emphasizeParenthesisLevel ifFalse:[ |
|
317 |
self |
|
318 |
markFrom:pos to:pos |
|
319 |
withEmphasis:(preferences bracketEmphasis) |
|
320 |
color:(preferences bracketColor). |
|
321 |
||
322 |
^ self |
|
323 |
]. |
|
324 |
||
325 |
level := currentBlock isNil ifTrue:[1] ifFalse:[currentBlock nestingLevel + 2]. |
|
326 |
(sourceText at:pos) = $] ifTrue:[ |
|
327 |
level := level - 1. |
|
328 |
]. |
|
329 |
||
330 |
colors := Array |
|
331 |
with:(Color black) |
|
332 |
with:(Color blue) |
|
333 |
with:(Color green blendWith:(Color grey:30)) |
|
334 |
with:(Color red blendWith:(Color grey:30)) |
|
335 |
with:(Color yellow darkened). |
|
336 |
||
337 |
clr := colors at:((level-1) \\ colors size + 1). |
|
338 |
em := #normal. |
|
339 |
level > 1 ifTrue:[ |
|
340 |
em := #bold. |
|
341 |
]. |
|
673 | 342 |
self |
343 |
markFrom:pos to:pos |
|
2070 | 344 |
withEmphasis:em |
345 |
color:clr |
|
673 | 346 |
! |
347 |
||
870 | 348 |
markClassVariableIdentifierFrom:pos1 to:pos2 |
349 |
self |
|
350 |
markFrom:pos1 to:pos2 |
|
1553 | 351 |
withEmphasis:(preferences classVariableIdentifierEmphasis) |
352 |
color:(preferences classVariableIdentifierColor) |
|
870 | 353 |
|
354 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
355 |
! |
|
356 |
||
662 | 357 |
markCommentFrom:pos1 to:pos2 |
358 |
self |
|
359 |
markFrom:pos1 to:pos2 |
|
1553 | 360 |
withEmphasis:(preferences commentEmphasis) |
361 |
color:(preferences commentColor) |
|
3353 | 362 |
font:(preferences commentFont) |
662 | 363 |
|
1550 | 364 |
" |
365 |
UserPreferences current commentEmphasis |
|
366 |
" |
|
367 |
"Modified: / 31.3.1998 / 18:01:55 / cg" |
|
662 | 368 |
! |
369 |
||
370 |
markConstantFrom:pos1 to:pos2 |
|
371 |
self |
|
372 |
markFrom:pos1 to:pos2 |
|
1553 | 373 |
withEmphasis:(preferences constantEmphasis) |
374 |
color:(preferences constantColor) |
|
662 | 375 |
|
376 |
"Modified: / 31.3.1998 / 18:01:44 / cg" |
|
377 |
"Created: / 31.3.1998 / 18:09:22 / cg" |
|
378 |
! |
|
379 |
||
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
380 |
markGlobalClassIdentifierFrom:pos1 to:pos2 |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
381 |
self |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
382 |
markFrom:pos1 to:pos2 |
1553 | 383 |
withEmphasis:(preferences globalClassIdentifierEmphasis) |
384 |
color:(preferences globalClassIdentifierColor) |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
385 |
|
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
386 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
387 |
"Created: / 4.3.1999 / 12:53:02 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
388 |
! |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
389 |
|
662 | 390 |
markGlobalIdentifierFrom:pos1 to:pos2 |
391 |
self |
|
392 |
markFrom:pos1 to:pos2 |
|
1553 | 393 |
withEmphasis:(preferences globalIdentifierEmphasis) |
394 |
color:(preferences globalIdentifierColor) |
|
662 | 395 |
|
396 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
397 |
! |
|
398 |
||
399 |
markHereFrom:pos1 to:pos2 |
|
400 |
self |
|
401 |
markFrom:pos1 to:pos2 |
|
1553 | 402 |
withEmphasis:(preferences hereEmphasis) |
403 |
color:(preferences hereColor) |
|
662 | 404 |
|
405 |
"Modified: / 31.3.1998 / 18:02:25 / cg" |
|
406 |
! |
|
407 |
||
408 |
markIdentifierFrom:pos1 to:pos2 |
|
409 |
self |
|
410 |
markFrom:pos1 to:pos2 |
|
1553 | 411 |
withEmphasis:(preferences identifierEmphasis) |
412 |
color:(preferences identifierColor) |
|
662 | 413 |
|
414 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
415 |
"Created: / 31.3.1998 / 18:04:56 / cg" |
|
416 |
! |
|
417 |
||
686 | 418 |
markInstVarIdentifierFrom:pos1 to:pos2 |
419 |
self |
|
420 |
markFrom:pos1 to:pos2 |
|
1553 | 421 |
withEmphasis:(preferences instVarIdentifierEmphasis) |
422 |
color:(preferences instVarIdentifierColor) |
|
686 | 423 |
|
424 |
"Created: / 16.4.1998 / 18:35:40 / cg" |
|
425 |
"Modified: / 16.4.1998 / 18:37:30 / cg" |
|
426 |
! |
|
427 |
||
662 | 428 |
markLocalIdentifierFrom:pos1 to:pos2 |
1802 | 429 |
cachedLocalIdentifierEmphasis isNil ifTrue:[ |
430 |
cachedLocalIdentifierEmphasis := preferences localIdentifierEmphasis. |
|
431 |
cachedLocalIdentifierColor := preferences localIdentifierColor. |
|
432 |
]. |
|
662 | 433 |
self |
434 |
markFrom:pos1 to:pos2 |
|
1802 | 435 |
withEmphasis:cachedLocalIdentifierEmphasis |
436 |
color:cachedLocalIdentifierColor |
|
662 | 437 |
|
438 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
439 |
! |
|
440 |
||
441 |
markMethodSelectorFrom:pos1 to:pos2 |
|
442 |
self |
|
443 |
markFrom:pos1 to:pos2 |
|
1553 | 444 |
withEmphasis:(preferences methodSelectorEmphasis) |
445 |
color:(preferences methodSelectorColor) |
|
662 | 446 |
|
447 |
"Modified: / 31.3.1998 / 18:02:52 / cg" |
|
448 |
! |
|
449 |
||
1684 | 450 |
markNumberConstantFrom:pos1 to:pos2 |
451 |
self |
|
452 |
markFrom:pos1 to:pos2 |
|
453 |
withEmphasis:(preferences numberConstantEmphasis) |
|
454 |
color:(preferences numberConstantColor) |
|
455 |
||
456 |
"Modified: / 31.3.1998 / 18:01:44 / cg" |
|
457 |
"Created: / 31.3.1998 / 18:09:22 / cg" |
|
458 |
! |
|
459 |
||
1640
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
460 |
markParenthesisAt:pos |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
461 |
|colors clr em| |
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 |
preferences emphasizeParenthesisLevel ifFalse:[^ self]. |
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 |
colors := Array |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
466 |
with:(Color black) |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
467 |
with:(Color blue) |
1757 | 468 |
with:(Color green blendWith:(Color grey:30)) |
469 |
with:(Color red blendWith:(Color grey:30)) |
|
1640
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
470 |
with:(Color yellow darkened). |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
471 |
|
1757 | 472 |
clr := colors at:((parenthesisLevel-1) \\ colors size + 1). |
1640
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
473 |
em := #normal. |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
474 |
parenthesisLevel > 1 ifTrue:[ |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
475 |
em := #bold. |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
476 |
]. |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
477 |
self |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
478 |
markFrom:pos to:pos |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
479 |
withEmphasis:em |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
480 |
color:clr |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
481 |
! |
261459ccc704
emphasize parenthesis nesting
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
482 |
|
1553 | 483 |
markPoolVariableIdentifierFrom:pos1 to:pos2 |
484 |
self |
|
485 |
markFrom:pos1 to:pos2 |
|
486 |
withEmphasis:(preferences poolVariableIdentifierEmphasis) |
|
487 |
color:(preferences poolVariableIdentifierColor) |
|
488 |
! |
|
489 |
||
838 | 490 |
markReturnAt:pos |
3598 | 491 |
"/ sourceText := (sourceText copyTo:pos-1),(Character value:16r21e7),(sourceText copyFrom:pos+1). |
838 | 492 |
self |
493 |
markFrom:pos to:pos |
|
1553 | 494 |
withEmphasis:(preferences returnEmphasis) |
495 |
color:(preferences returnColor) |
|
838 | 496 |
|
497 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
|
498 |
"Created: / 5.1.1980 / 00:44:27 / cg" |
|
499 |
! |
|
500 |
||
863 | 501 |
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
|
502 |
|fg selectorSymbol check ok rec em| |
863 | 503 |
|
504 |
"/ uncommenting the code below |
|
505 |
"/ will suppress highlighting of common selectors ... |
|
506 |
"/ |
|
507 |
"/ (#( |
|
508 |
"/ 'ifTrue:' |
|
509 |
"/ 'ifFalse:' |
|
510 |
"/ 'not' |
|
511 |
"/ 'and:' |
|
512 |
"/ 'or:' |
|
513 |
"/ '=' |
|
514 |
"/ '==' |
|
515 |
"/ '~=' |
|
516 |
"/ '~~' |
|
517 |
"/ ) includes:sel) ifTrue:[ |
|
518 |
"/ ^ self |
|
519 |
"/ ]. |
|
520 |
||
1526 | 521 |
fg := preferences selectorColor. |
522 |
em := preferences selectorEmphasis. |
|
1498
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
523 |
selectorSymbol := selectorString asSymbolIfInterned. |
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
524 |
selectorSymbol isNil ifTrue:[ |
1905 | 525 |
em := preferences unimplementedSelectorEmphasis. |
526 |
fg := preferences unimplementedSelectorColor. |
|
1498
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
527 |
] ifFalse:[ |
1905 | 528 |
ok := true. |
529 |
||
863 | 530 |
fullSelectorCheck == true ifTrue:[ |
531 |
||
1498
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
532 |
check := [:cls | (cls includesSelector:selectorSymbol) |
9b4366551a2a
speed up symbol checking and generation
Stefan Vogel <sv@exept.de>
parents:
1396
diff
changeset
|
533 |
or:[cls class includesSelector:selectorSymbol]]. |
863 | 534 |
|
535 |
ok := false. |
|
536 |
||
537 |
"/ limit search if possible |
|
538 |
(classToCompileFor notNil |
|
539 |
and:[aReceiverNode isSelf or:[aReceiverNode isSuper]]) ifTrue:[ |
|
540 |
currentSuperclasses isNil ifTrue:[ |
|
541 |
currentSuperclasses := classToCompileFor withAllSuperclasses. |
|
542 |
]. |
|
543 |
ok := currentSuperclasses contains:check. |
|
544 |
(ok not and:[aReceiverNode isSelf]) ifTrue:[ |
|
545 |
currentSubclasses isNil ifTrue:[ |
|
546 |
currentSubclasses := classToCompileFor allSubclasses. |
|
547 |
]. |
|
548 |
ok := currentSubclasses contains:check. |
|
549 |
]. |
|
550 |
] ifFalse:[ |
|
3816 | 551 |
aReceiverNode isLiteral ifTrue:[ |
863 | 552 |
ok := aReceiverNode evaluate class withAllSuperclasses contains:check. |
553 |
] ifFalse:[ |
|
554 |
(aReceiverNode isGlobal |
|
555 |
and:[(rec := aReceiverNode evaluate) isBehavior]) ifTrue:[ |
|
556 |
ok := rec class withAllSuperclasses contains:check. |
|
557 |
] ifFalse:[ |
|
558 |
ok := Smalltalk allClasses contains:check |
|
559 |
] |
|
560 |
] |
|
561 |
]. |
|
1905 | 562 |
]. |
3232 | 563 |
|
1905 | 564 |
ok ifFalse:[ |
565 |
em := preferences unimplementedSelectorEmphasis. |
|
566 |
fg := preferences unimplementedSelectorColor. |
|
567 |
] ifTrue:[ |
|
3343 | 568 |
(self class isControlFlowSelector:selectorSymbol) ifTrue:[ |
1905 | 569 |
em := preferences controlFlowSelectorEmphasis. |
2816
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
570 |
fg := preferences controlFlowSelectorColor |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
571 |
] ifFalse:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
572 |
(self collectionEnumerationSelectors includesIdentical:selectorSymbol) ifTrue:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
573 |
em := preferences collectionEnumerationSelectorEmphasis. |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
574 |
fg := preferences collectionEnumerationSelectorColor |
3229 | 575 |
] ifFalse:[ |
576 |
(self debugSelectors includesIdentical:selectorSymbol) ifTrue:[ |
|
577 |
em := preferences debugSelectorEmphasis. |
|
578 |
fg := preferences debugSelectorColor |
|
579 |
] ifFalse:[ |
|
580 |
(self errorRaisingSelectors includesIdentical:selectorSymbol) ifTrue:[ |
|
581 |
em := preferences errorRaisingSelectorEmphasis. |
|
582 |
fg := preferences errorRaisingSelectorColor |
|
583 |
]. |
|
584 |
]. |
|
2816
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
585 |
]. |
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 |
em isNil ifTrue:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
588 |
em := preferences selectorEmphasis |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
589 |
]. |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
590 |
fg isNil ifTrue:[ |
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
591 |
fg := preferences selectorColor |
1905 | 592 |
]. |
593 |
]. |
|
863 | 594 |
]. |
595 |
self |
|
596 |
markFrom:pos1 to:pos2 |
|
1553 | 597 |
withEmphasis:em |
598 |
color:fg |
|
863 | 599 |
|
2816
e8b84f6d7462
changed: #markSelector:from:to:receiverNode:
Claus Gittinger <cg@exept.de>
parents:
2811
diff
changeset
|
600 |
"Modified: / 14-02-2012 / 16:03:52 / cg" |
863 | 601 |
! |
602 |
||
662 | 603 |
markSelfFrom:pos1 to:pos2 |
604 |
self |
|
605 |
markFrom:pos1 to:pos2 |
|
1553 | 606 |
withEmphasis:(preferences selfEmphasis) |
607 |
color:(preferences selfColor) |
|
662 | 608 |
|
609 |
"Modified: / 31.3.1998 / 18:03:10 / cg" |
|
610 |
! |
|
611 |
||
612 |
markStringFrom:pos1 to:pos2 |
|
1802 | 613 |
cachedStringEmphasis isNil ifTrue:[ |
614 |
cachedStringEmphasis := preferences stringEmphasis. |
|
615 |
cachedStringColor := preferences stringColor. |
|
616 |
]. |
|
662 | 617 |
self |
618 |
markFrom:pos1 to:pos2 |
|
1802 | 619 |
withEmphasis:cachedStringEmphasis |
620 |
color:cachedStringColor |
|
662 | 621 |
|
622 |
"Modified: / 31.3.1998 / 18:03:18 / cg" |
|
623 |
! |
|
624 |
||
625 |
markSuperFrom:pos1 to:pos2 |
|
626 |
self |
|
627 |
markFrom:pos1 to:pos2 |
|
1553 | 628 |
withEmphasis:(preferences superEmphasis) |
629 |
color:(preferences superColor) |
|
662 | 630 |
|
631 |
"Modified: / 31.3.1998 / 18:03:26 / cg" |
|
632 |
! |
|
633 |
||
672 | 634 |
markSymbolFrom:pos1 to:pos2 |
635 |
self |
|
636 |
markFrom:pos1 to:pos2 |
|
1553 | 637 |
withEmphasis:(preferences symbolEmphasis) |
638 |
color:(preferences symbolColor) |
|
672 | 639 |
|
640 |
"Created: / 1.4.1998 / 12:56:47 / cg" |
|
641 |
"Modified: / 1.4.1998 / 12:58:00 / cg" |
|
642 |
! |
|
643 |
||
662 | 644 |
markThisContextFrom:pos1 to:pos2 |
645 |
self |
|
646 |
markFrom:pos1 to:pos2 |
|
1553 | 647 |
withEmphasis:(preferences thisContextEmphasis) |
648 |
color:(preferences thisContextColor) |
|
662 | 649 |
|
650 |
"Modified: / 31.3.1998 / 18:03:36 / cg" |
|
665 | 651 |
! |
652 |
||
653 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
654 |
self |
|
655 |
markFrom:pos1 to:pos2 |
|
1553 | 656 |
withEmphasis:(preferences unknownIdentifierEmphasis) |
657 |
color:(preferences unknownIdentifierColor) |
|
665 | 658 |
|
659 |
"Created: / 31.3.1998 / 19:09:26 / cg" |
|
660 |
"Modified: / 31.3.1998 / 19:10:30 / cg" |
|
686 | 661 |
! |
662 |
||
3187 | 663 |
markVariable:v from:pos to:endPos assigned:assigned |
686 | 664 |
"support for syntaxColoring" |
665 |
||
823 | 666 |
|type globalValue nameSym| |
686 | 667 |
|
668 |
type := v type. |
|
669 |
(type == #BlockArg |
|
670 |
or:[type == #MethodArg]) ifTrue:[ |
|
671 |
self markArgumentIdentifierFrom:pos to:endPos. |
|
672 |
^ self |
|
673 |
]. |
|
674 |
(type == #BlockVariable |
|
675 |
or:[type == #MethodVariable]) ifTrue:[ |
|
676 |
self markLocalIdentifierFrom:pos to:endPos. |
|
677 |
^ self |
|
678 |
]. |
|
679 |
(type == #GlobalVariable) ifTrue:[ |
|
823 | 680 |
nameSym := v name asSymbolIfInterned. |
681 |
nameSym notNil ifTrue:[ |
|
682 |
globalValue := Smalltalk at:nameSym ifAbsent:nil. |
|
683 |
]. |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
684 |
globalValue isBehavior ifTrue:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
685 |
self markGlobalClassIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
686 |
] ifFalse:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
687 |
self markGlobalIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
688 |
]. |
686 | 689 |
^ self |
690 |
]. |
|
1553 | 691 |
(type == #PoolVariable) ifTrue:[ |
692 |
self markPoolVariableIdentifierFrom:pos to:endPos. |
|
693 |
^ self |
|
694 |
]. |
|
870 | 695 |
(type == #ClassVariable) ifTrue:[ |
696 |
self markClassVariableIdentifierFrom:pos to:endPos. |
|
697 |
^ self |
|
698 |
]. |
|
686 | 699 |
(type == #InstanceVariable) ifTrue:[ |
700 |
self markInstVarIdentifierFrom:pos to:endPos. |
|
701 |
^ self |
|
702 |
]. |
|
703 |
||
704 |
self markIdentifierFrom:pos to:endPos. |
|
705 |
||
706 |
"Created: / 16.4.1998 / 18:49:34 / cg" |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
707 |
"Modified: / 4.3.1999 / 12:56:13 / cg" |
662 | 708 |
! ! |
709 |
||
710 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
711 |
||
712 |
version |
|
3816 | 713 |
^ '$Header$' |
2228 | 714 |
! |
715 |
||
716 |
version_CVS |
|
3816 | 717 |
^ '$Header$' |
662 | 718 |
! ! |
2997 | 719 |